简体   繁体   中英

JSON path expression to fetch keys of nested objects

what is the JSON path expression to fetch "item1" , "item2" without knowing in advance the names of these keys.

{
"item_group" : "This is item group",
"items": {
"item1": {
  "name1": "value1",
  "name2": {
    "value2": "value2"
  },
  "name3": {
    "param1": "This is param1"
  }
},
"item2": {
  "name11": "value11",
  "name22": {
    "value22": "value22"
  },
  "name33": {
    "param2": "This is param2"
  }
}
}
}

You probably want dict["items"].items() . It will return a list of key/value tuples. For an example iterating over the keys:

for key, _ in dict["items"].items():
    pass

for..in loop worked!

for(var prop in obj) {
   console.log("Key_Name: " + prop);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM