0


I have a JSON structure like this :

{
    "cars": {
        "Nissan": [
            {"model":"Sentra", 
             "doors":4},
            {"model":"Maxima", 
             "doors":4}
        ],
        "Ford": [
            {"model":"Taurus", 
             "doors":4},
            {"model":"Escort", 
             "doors":4}
        ]
    }
}


I will enter key , output should print entire path till that key.
For example :
For Nissan ,first array:

Input :model , Output:cars->Nissan[0].model<br/>
Input:doors ,  Output:cars->Nissan[0].doors<br/>

For Nissan ,second array:

Input :model , Output:cars->Nissan[1].model<br/>

So, like that I want full path for every JSON field.
I tried Jackson framework to achieve this, but got no success.
Please help..

alessandrio
  • 4,282
  • 2
  • 29
  • 40
mayank bisht
  • 618
  • 3
  • 14
  • 43
  • Nissan first array and second array, input and output both are same ? – Ashraful Islam May 26 '17 at 18:31
  • How you gonna use this output? – eg04lt3r May 26 '17 at 19:05
  • 1
    If you want to get values from json via paths, I think you can try jayway jsonpath library. Check the link please https://github.com/json-path/JsonPath. – eg04lt3r May 26 '17 at 19:15
  • @eg04lt3r: Actually I want to retrieve mapping of each node present in json.The reason being if the user want to fetch any particular node, he use this mapping directly. – mayank bisht May 27 '17 at 03:32
  • @eg04lt3r :Thanks for the link, But Jayway also uses JSON paths to retrieve values.I want to generate that json path for each node present in the json. For e.g like this **$.store.book[*].author** – mayank bisht May 27 '17 at 03:35
  • @eg04lt3r : I came across this question **https://stackoverflow.com/questions/33224048/how-do-i-get-a-list-of-all-json-paths-to-values-from-a-json-string** , it's similar to my requirement .But I cannot run this code on my machine . – mayank bisht May 27 '17 at 04:08
  • @eg04lt3r : Any suggestions ? – mayank bisht May 28 '17 at 03:04
  • @mayankbisht, do you use any build tool for your project? If yes seems like you should provide missed dependency from maven repo https://mvnrepository.com/artifact/org.json/json/20170516. If no, you can download missed jar from the same page and add it to classpath of your application. – eg04lt3r May 29 '17 at 18:01

0 Answers0