1

I'm trying to filter simple JSON data and export keys with similar values using the JMESPath query. This is my JSON.

{
  "af": "0",
  "al": "2",
  "dz": "0",
  "ad": "2",
  "ao": "1",
  "ag": "2",
  "ar": "2",
  "am": "2",
  "au": "3",
  "at": "2"
}

Desired output would be this if I specify "0"

{
  "af",
  "dz"
}

My current query is keys(@)[?contains(@, '0')] but it returns empty array.

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
DaftPlug
  • 60
  • 1
  • 10
  • 1
    As you might have seen testing `keys(@)`, this destroys the values, so you cannot filter by value on the resulting JSON anymore. A way to filter on an object is to do `*|[?contains(@, '0')]`, but unfortunately, this have the opposite effect, which is to destroy the keys. So, what you are looking for is not feasible in the current version of JMESPath. – β.εηοιτ.βε Aug 01 '22 at 09:43

0 Answers0