Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of object keys in JMESPath

Tags:

json

jmespath

My Google search skills are failing me. How to get a list of all JSON object keys in JMESPath?

i.e. how to go from:

{"a": 1, "b": 2}

to:

["a", "b"]
like image 442
Haitham Gad Avatar asked Oct 05 '17 16:10

Haitham Gad


1 Answers

JMESPath has the function keys. Therefore, the JMESPath expression is keys(@).

Example

echo '{"a": 1, "b": 2}' | jp "keys(@)"

returns

[
  "a",
  "b"
]

Tested with jp 0.1.3 on a Linux environment.

like image 107
pareyesv Avatar answered Sep 23 '22 05:09

pareyesv