0

I am trying to get all the parent / ancestor's name of a fields in a json array.

For suppose i have the following json array

    {
    "country abbreviation": "US",
    "places": [
        {
            "place name": {
            "state": "india",
            "continent": "Asia"
            },
            "longitude": "-71.4594",
            "post code": "02178",
            "latitude": "42.4464"
        },
        {
            "place name": "Belmont",
            "longitude": "-71.2044",
            "post code": "02478",
            "latitude": "42.4128"
        }
    ],
    "country": "United States",
    "place name": "Belmont",
    "state": "Massachusetts",
    "state abbreviation": "MA"
    }

And if want to get the parent / ancestor's name of state then it should be "place/place name"

i am trying to do it using python, but can't understand the logic,can anyone help me. Using shell will also work, but primarily i want it in python.

ggupta
  • 675
  • 1
  • 10
  • 27
  • You can't do that directly. This is not how JSON works. You'll need to search for the item you want, and "remember" what was the item before/"above" that. – DeepSpace May 10 '17 at 10:14
  • 1
    http://stackoverflow.com/questions/38689645/jq-how-to-i-print-a-parent-value-of-an-object-when-i-am-already-deep-into-the – grundic May 10 '17 at 10:19
  • @DeepSpace i think we can do this, may be i'm wrong but let's see what other geeks say. thanks! – ggupta May 10 '17 at 10:19
  • @grundic link attached is about something different i guess – ggupta May 10 '17 at 10:21
  • 1
    @mike trying to fetch all the tags or fields, and then match with what i required, and then its value. Probably post the answer tomorrow, its under progress – ggupta May 10 '17 at 12:02
  • 1
    @mike i have posted the answer, you can check it http://guptagauravdevprofile.blogspot.com/2017/05/get-all-fields-or-header-or-keys-with.html – ggupta May 25 '17 at 10:33

0 Answers0