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
55
votes
11 answers

XPath like query for nested python dictionaries

Is there a way to define a XPath type query for nested python dictionaries. Something like this: foo = { 'spam':'eggs', 'morefoo': { 'bar':'soap', 'morebar': {'bacon' : 'foobar'} } } print(…
RickyA
  • 15,465
  • 5
  • 71
  • 95
32
votes
2 answers

Filter S3 list-objects results to find a key matching a pattern

I would like to use the AWS CLI to query the contents of a bucket and see if a particular file exists, but the bucket contains thousands of files. How can I filter the results to only show key names that match a pattern? For example: aws s3api…
dnlbrky
  • 9,396
  • 2
  • 51
  • 64
28
votes
3 answers

Listing instance name among other data with aws-cli 1.3.6

Using aws-cli 1.3.6 I am trying to get a simple table of my ec2 instances with the Name and state. I have been looking at the --query and JMESpath documentation and I have been able to select the "Value" item of a Map which "Key" item is equal to…
c-garcia
  • 598
  • 1
  • 9
  • 17
27
votes
1 answer

JMESPath JSON filter with multiple matches

I have a json block that looks a bit like this (have you guessed from AWS) { "Vpcs":[ { "VpcId":"vpc-blabla1", "OtherKey":"Value" }, { "VpcId":"vpc-blabla2", "OtherKey":"Value" }, { "VpcId":"vpc-blabla3", …
Sam
  • 602
  • 1
  • 6
  • 10
24
votes
4 answers

Filter object by property and select with key in jmespath

I'm trying to filter properties of an object in jmespath based on the value of a subproperty and want to include only those properties where the subproperty is set to a specific value. Based on this example data: { "a": { "feature": { …
Johannes Müller
  • 5,581
  • 1
  • 11
  • 25
22
votes
1 answer

How to search with case insensitive regex using JMESPath

I need to work with some systems that use JMESPath to search JSON. How can I search for strings with pattern (like this). How do I do this with a regular expression in case-insensitive mode? P.S.: Not sure why AWS S3 CLI, and Ansible use JMESPath…
HKTonyLee
  • 3,111
  • 23
  • 34
22
votes
4 answers

sort output of describe-instances?

I saw the previous question on this topic, but the answer was just "pipe it to a scripting language!", which I find unsatisfying. I know that JMESPath has sort_by, and sort, but I can't figure out how to use them. I have aws ec2…
ColinK
  • 438
  • 1
  • 3
  • 8
20
votes
2 answers

JMESPath query expression with bash variable

Messing around with a simple aws cli query to check for the existence of a Lambda function and echo the associated role if it exists: #!/bin/bash fname=$1 role=$(aws lambda list-functions --query 'Functions[?FunctionName == `$fname`].Role' --output…
TomH
  • 2,950
  • 2
  • 26
  • 49
18
votes
3 answers

How to handle JMESPath contains filter on attribute that may be null?

I want to filter the output from the Azure CloudShell command az ad sp list which outputs a JSON array, eg by filtering to Publisher Name = "ACME". All az commands support a --query argument which accepts a JMESPath expression. I have a JMESPath…
JohnC
  • 1,797
  • 1
  • 18
  • 26
18
votes
4 answers

Parse raw string as object using JMESPath

I have an object that I am parsing using JMESPath where the value of a property is a JSON object encoded as a string. I want to be able to parse that string property as a JSON Object and work with it using JMESPath only (I'm aware I could parse the…
mixja
  • 6,977
  • 3
  • 32
  • 34
18
votes
2 answers

Count the number of instances in an array using JMESPath

In the example JSON at the bottom of this question, how can I count the number of key/value pairs in the array "Tags" using JMESPath? According to the JMESPath documentation, I can do this using the count() function - For example, the following…
David Gard
  • 11,225
  • 36
  • 115
  • 227
17
votes
2 answers

Sort by date with jmespath

With a json output like : { "Functions":[ { "CodeSha256":"7NBvXXacp9x3aK3cKaI=", "FunctionName":"function_1", "FunctionArn":"arn:aws:lambda:eu-west-1:1111:function:function_1", …
Mio
  • 1,412
  • 2
  • 19
  • 41
16
votes
1 answer

Case-insensitive search with JMESPath

The question is simple. How to do a case-insensitive searching with JMESPath? Let's say to search for foo in this JSON: [ "foo", "foobar", "barfoo", "bar", "baz", "barbaz", "FOO" ] Here is the case-sensitive search…
HKTonyLee
  • 3,111
  • 23
  • 34
14
votes
1 answer

How to get a list of object keys in JMESPath

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"]
Haitham Gad
  • 1,529
  • 2
  • 13
  • 23
12
votes
1 answer

Querying multiple values

I'm trying to filter by multiple values however I can't seem to get an and clause to work (e.g. filter1 and filter 2 ... etc.): Show me snapshots where the database name is 'testing' aws rds describe-db-snapshots --include-shared --query…
bob dylan
  • 1,458
  • 1
  • 14
  • 32
1
2 3
32 33