Search code examples
jsonjmespath

Getting first level with JMESPath


I have this JSON document:

{
"1": {
    "a": "G1"
},
"2": {
    "a": "GM1"
}
}

My expected result should be:

1,G1
2,GM1

With *.a i get

[
  "G1",
  "GM1"
]

but I am absolutely stuck for the rest.


Solution

  • Finally this expression worked 100% for me:

    [{key1:keys(@)[0],a:*.a| [0]},{key1:keys(@)[1],a:*.a| [1]}]