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
5
votes
3 answers

How to perform substring like function in jmespath on a string

I would like to know if there is substring function one can leverage in JMESPATH (supported by az cli). I have the below az cli request and I want to just extract the name of the linked subnet with a security group, but unlike other cloud providers…
koss
  • 107
  • 1
  • 7
5
votes
1 answer

Escape '.' in JMESPath

I have a JSON object in which I wish to retrieve the value of a property that contains a dot in its name using JMESPath: { "a": { "b.c": "value" } } In this example I wish to retrieve value. How can I achieve this?
Thorkil Holm-Jacobsen
  • 7,287
  • 5
  • 30
  • 43
5
votes
1 answer

Filtering list of objects with json values using JMESPATH

I have a JSON and I need to select the value of the persons roles using JMESPATH. I can do it with only one and static id, like roles[?id=='1324'], but I can't do with a list of roles ids and selected from the JSON. I tried to do that with:…
5
votes
1 answer

JMESPath - Joining items in a nested array

I have a JSON { "key": "processId-29231", "fields": { "attachment": [ { "id": "79572", "filename": "File1.png" }, { "id": "74620", "filename": "File2.docx" }, …
user9445
  • 455
  • 5
  • 15
5
votes
2 answers

Using keys from the json src doc in a multiselect hash with Jmespath

I have a source json document that looks like this: # Source json { "nics": { "vlan_internal": { "mac": "aa:aa:aa:aa:aa:aa" }, "vlan_external": { "mac": "aa:aa:aa:aa:aa:bb" } } } Using ansible's json_query filter…
loudsong
  • 121
  • 1
  • 6
5
votes
1 answer

ansible json-query path to select item by content

Does anyone know what json-query filter can be used to select Tigger's food in the sample JSON below? The JSON is a simplified stand-in for a massive and relatively complicated AWS blob. Some background: I was rather pleased to discover that…
Max Murphy
  • 1,701
  • 1
  • 19
  • 29
5
votes
2 answers

Reference Parent Element in JMESPath Filter Expression

I have the following JMESPath query query="Reservations[].Instances[].{ \ InstanceId: InstanceId, \ RootDeviceVolumeId: BlockDeviceMappings[?DeviceName==\`/dev/sda1\`] \ | [].Ebs.VolumeId | [0], \ RootDeviceName: RootDeviceName…
Joe Taylor
  • 2,145
  • 1
  • 19
  • 35
4
votes
2 answers

How to get key and value instead of only value when filtering with JMESPath?

Input data: s = {'111': {'name': 'john', 'exp': '1'}, '222': {'name': 'mia', 'exp': '1'}} Code: import jmespath jmespath.search("(*)[?name=='john']", s) Output: [{'name': 'john', 'exp': '1'}] Output I want: [{'111': {'name': 'john', 'exp':…
SkruDJ
  • 157
  • 8
4
votes
1 answer

AWS describe-instances filter by tag and exclude by tag

In the new AWS console I can do inverse search, i.e.: search that does not match a certain value, with a filter. I am trying to achieve the same using the AWS cli v2. It's straight forward to filter by tag but how do I exclude a tag at the same…
Phil
  • 43
  • 4
4
votes
1 answer

How can I get jmespath filter to return true if the value exists and false if it doesn't (python)

This is an extension from a previous question that is unresolved but another way of looking at the problem HERE { "name": "Sarah", "region": "south west", "age": 21, "occupation": "teacher", "height": 145, "education": "university", …
schosen
  • 61
  • 1
  • 5
4
votes
1 answer

AWS cli JMESpath query tag values

As a follow-up to my previous question, I am having trouble getting tags to work right in this type of output. I want to print a table with each property as a row. This is how I expect it to look: % aws --output table ec2 describe-instances…
Elliott B
  • 980
  • 9
  • 32
4
votes
2 answers

Filter elements containing string with JMESPath

I want to get a list of addresses of a defined interface type. I found some info here. Here is my playbook: - name: Test JMESPath hosts: localhost gather_facts: no vars: interfaces: - name: em0 address: 10.127.37.89/29 -…
mooky
  • 87
  • 5
4
votes
1 answer

aws cli query multiple attributes when these attributes are on the same level

I am using the following to find information about instances associated with a particular Security Group aws ec2 describe-network-interfaces --filters Name=group-id,Values=sg-123456 --output json this returns (partial output) { …
4
votes
1 answer

How to set a default value for null values in JMESPath query when using AWS CLI?

I'm trying to run a command with AWS CLI with query. The command could be something simple like aws s3api list-buckets --query 'sum(Versions[*].Size)' However, occasionally, some values can return null. In the example above, size can be null when…
Carven
  • 14,988
  • 29
  • 118
  • 161
4
votes
2 answers

Can JMESPATH perform a "contains X or Y" search/filter?

Is it possible to move the preg_match search below into the JMESPATH search filter using contains? I found an example of contains in the JMESPATH tutorial, but I'm not sure if the syntax supports combining filter strings somehow using OR. …
Matt V.
  • 9,703
  • 10
  • 35
  • 56
1 2
3
32 33