Home > Software design >  Extracting keys from JMESPath expression in objects
Extracting keys from JMESPath expression in objects

Time:08-03

I would like to extract the keys from those JSON objects in a JMESPath expression:

{"wrapperType": "track", "kind": "song", "artistId": 657515}

And this, independently of the values.

My main goal is to get something like this:

["wrapperType", "kind", "artistId"]

I did find how to filter values without any problem but I am unable to find something that extracts keys.

CodePudding user response:

This can be achieved with the keys function, that you can use on the current node: @.

On your example, running the query

keys(@)

Would give the expected JSON:

[
  "wrapperType",
  "kind",
  "artistId"
]
  • Related