1

How would I get the names of the keys, for example [800, 801] (the key names are unknown) with objectpath. It is easy in jmespath: keys(@).

  "groups": {
    "800": {
      "short_name": "22",
      "oname": "11",
      "group": 8,
      "title": "SS",
      "name": "33",
      "onames": [""],
      "alt_name": False,
      "waytype": 1,
      "multiple": 1,
      "primary": 1
    },
    "801": {
      "short_name": "ss",
      "oname": "zz",
      "group": 8,
      "title": "ss",
      "name": "bbb",
      "onames": [""],
      "alt_name": False,
      "waytype": 1,
      "multiple": 1,
      "primary": 0
    },
abruski
  • 851
  • 3
  • 10
  • 27
  • Take a a look at [`dict.keys()`](https://docs.python.org/3/library/stdtypes.html#dict.keys). Potencial duplicate of https://stackoverflow.com/questions/43950626/python-getting-keys-of-a-dictionary – tread Aug 30 '19 at 11:01

1 Answers1

-1

let your object is assigned to name variable

const name = {    "groups": {

    "800": {
      "short_name": "22",
      "oname": "11",
      "group": 8,
      "title": "SS",
      "name": "33",
      "onames": [""],
      "alt_name": false,
      "waytype": 1,
      "multiple": 1,
      "primary": 1
    },
    "801": {
      "short_name": "ss",
      "oname": "zz",
      "group": 8,
      "title": "ss",
      "name": "bbb",
      "onames": [""],
      "alt_name": false,
      "waytype": 1,
      "multiple": 1,
      "primary": 0
    }   } }

Use for loop to get the key name as

 for(var num in name.groups) {   
        console.log(num);
    }

and to get the values of key

for(var num in name.groups) {
  console.log(name.groups[num]);
}
Rupesh
  • 850
  • 2
  • 13
  • 30