How to get a list of object keys in JMESPath
Asked Answered
I

1

15

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"]
Interruption answered 5/10, 2017 at 16:12 Comment(0)
A
21

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.

Abscission answered 13/10, 2017 at 15:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.