Questions tagged [jmespath]

JMESPath (JSON Matching Expression paths) is a query language for JSON. JMESPath allows you to extract elements from a JSON document. It also allows you to directly transform the queried elements.

JMESPath (JSON Matching Expression Paths) is a query language for .

In addition to allowing you to extract elements from a JSON document, it also allows you to transform the queried elements.

In other words: JMESPath is to JSON what is to .

For questions about JSON itself, please use the tag.

Useful Links:

495 questions
12
votes
2 answers

Dynamic/computed keys in JMESPath?

From ES2015 with computed properties and Array.reduce/Array.map/Object.assign you can do: [{name: 'foo', age: 43}, {name: 'bar', age: 55}].map( o => ({[o.name]: o.age})).reduce((a, b) => Object.assign(a,b), {}) …and get: { foo: 43, bar: 55…
A T
  • 13,008
  • 21
  • 97
  • 158
12
votes
3 answers

How can I get unique values in array in a jmespath query?

In an aws cli jmespath query, with for example the output ["a","a","b","a","b"], how do i extract the unique values of it to get ["a","b"]?
Frido Emans
  • 5,120
  • 2
  • 27
  • 42
11
votes
2 answers

How to get list of all child elements with field from parent

I have list of dicts that contains another list in one of fields. I want to "flatten" that list, so it gives me every subelement with one field (or some fields) from parent copied into it. Example: Source data: [ { "name": "A", …
GwynBleidD
  • 20,081
  • 5
  • 46
  • 77
10
votes
1 answer

AZ CLI query filter on multiple properties using &&

I am trying to create an az cli query that can evaluate if I am logged into the correct tenant and subscription. I know I have to use the ? and && operators but have not been able to get them in the correct combination yet that will work. When I…
phydeauxman
  • 1,432
  • 3
  • 26
  • 48
9
votes
1 answer

Filter a simple array with JMESPath

I'm trying to filter a plain list I get from the Azure CLI, and am struggling to construct a query that filters the list properly. An example which encapsulates what I'm trying to accomplish would be trying to filter the list [1, 2, 3, 4, 5] and…
Marcus
  • 3,216
  • 2
  • 22
  • 22
9
votes
1 answer

JmesPath find where not exists

The following JmesPath expression finds instances that have been tagged with a team: "Instances[?Tags[?Key=='team']]" Do you know how to find instances that are not tagged with a team? I have tried: "Instances[?!Tags[?Key=='team']]" ->…
Max Murphy
  • 1,701
  • 1
  • 19
  • 29
9
votes
1 answer

Filter output based on the existence of multiple key/value pairs

Using JMESPath, is it possible to filter output based on the existence of multiple key/value pairs within the input? From the example JSON below, what I'd like to do is extract only the objects that contain these key/value pairs within Tags…
David Gard
  • 11,225
  • 36
  • 115
  • 227
9
votes
2 answers

How to combine two arrays (`keys` and `values`) into an object using JMESPath?

I have a JSON object with two arrays — one keys array and one values array, both of the same length. Using jmespath, I want to construct a new object using the values of the keys array as the keys and the values of the values array as the values,…
jagwar3
  • 95
  • 1
  • 6
8
votes
3 answers

How to filter dictionaries in Jinja?

I have a dictionary of packages with package-name being the key and a dictionary of some details being the value: { "php7.1-readline": { "latest": "7.1.9-1+ubuntu14.04.1+deb.sury.org+1", "origins": [ …
Mikhail T.
  • 3,043
  • 3
  • 29
  • 46
7
votes
2 answers

JMESPathTypeError when using json_query filter in Ansible with starts_with

I am trying to filter results that arrived from boto3 in Ansible. When I use json query on the results without the "[?starts_with(...)]" it works well, but when adding the starts_with…
7
votes
2 answers

AWS CLI and JMESPath filter and select on nested properties

I want to use the CLI tool, to retrieve the distribution-id of a CloudFront distribution with a specific cname/alias. This is what I came up with: aws cloudfront list-distributions --query…
Jeroen Jacobs
  • 1,423
  • 3
  • 16
  • 32
6
votes
0 answers

JMESPath search nested data for key

I am trying to use the Python Library for JMESPath to extract information from a large JSON file, a much simplified example is here: { "high_name":"test", "sections":[ { "name":"section1", "item":"string1" }, { …
ck3mp
  • 391
  • 5
  • 18
6
votes
3 answers

JMESPath expression to flatten array of objects, each with nested arrays of objects

I have JSON containing an array of databases, each database has an array of users, e.g. {"databases": [ {"db": "db_a", "users": [{"name": "alice"}, {"name": "alex"}]}, {"db": "db_b", "users": [{"name": "bob"}, {"name": "brienne"}]} ]} I would…
Alex Willmer
  • 491
  • 4
  • 14
6
votes
1 answer

Filtering JMESPath with contains

JMESPath is a query language for JSON, used by Azure. Using its own example given from http://jmespath.org/ { "locations": [ {"name": "Seattle", "state": "WA"}, {"name": "New York", "state": "NY"}, {"name": "Bellevue", "state":…
xpt
  • 20,363
  • 37
  • 127
  • 216
5
votes
1 answer

Filter by partial string match in JSON using JMESPath

Below is a sample JSON: { "School": [ {"@id": "ABC_1", "SchoolType": {"@tc": "10023204", "#text": "BLUE FOX"}}, {"@id": "ABC_2", "SchoolType": {"@tc": "143", "#text": "AN EAGLE"}}, {"@id": "ABC_3", "SchoolType": {"@tc": "21474836",…
Debbie
  • 391
  • 2
  • 18
1
2
3
32 33