0

We have output from pig stored in a text file. They are tuples containing a user path in the form of urls.

Here are 2 sample tuples:

    (http://www.flipkart.com/",http://www.flipkart.com/jewellery",http://www.flipkart.com/jewellery/rings",http://www.flipkart.com/jewellery/rings/Agni"):1
(http://www.flipkart.com/",http://www.flipkart.com/jewellery",http://www.flipkart.com/jewellery/rings",http://www.flipkart.com/jewellery/rings/Nakshatra"):1

We want our output in the form of a nested json:

{"id":0,      
"name":"(http:\/\/www.flipkart.com\/\"",
"data":"",
"children":
{"id":1,
"name":"http:\/\/www.flipkart.com\/jewellery\"",
"data":"",
"children":
    {"id":2,
    "name":"http:\/\/www.flipkart.com\/jewellery\/rings\"",
    "data":"","children":
        [{"id":3,
        "name":"http:\/\/www.flipkart.com\/jewellery\/rings\/Agni\"):1",
        "data":"",
        "children":"[]"
        },
        {"id":4,
        "name":"http:\/\/www.flipkart.com\/jewellery\/rings\/Nakshatra\"):1",
        "data":"",
        "children":"[]"
        }]
    }
}
}

How can we do this in java?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Madhura Desai
  • 13
  • 1
  • 5
  • sounds like this is what you need http://stackoverflow.com/questions/4105795/pretty-print-json-in-java – Hector Jun 03 '15 at 08:12

1 Answers1

0

There is not shortcut - you need to clean the string and make Json. I guess you are trying to make a jstree?

If you want to do in Javascript - write a regex, run a loop to add other variables and convert the JSON.stringify method to convert to Json object. Or in case of java clean the string, make pojo and create a json object using GSON or any other library.

Sheetal Mohan Sharma
  • 2,908
  • 1
  • 23
  • 24