medisamm
medisamm

Reputation: 331

Extracting keys from JMESPath expression in objects

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.

Upvotes: 3

Views: 644

Answers (1)

β.εηοιτ.βε
β.εηοιτ.βε

Reputation: 39129

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"
]

Upvotes: 4

Related Questions