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 . JMESPath allows you to extract elements from a JSON document. It also allows you to directly transform the queried elements. So to speak, JMESPath is for JSON what is for . For questions on JSON itself please use the tag.

Useful Links:

295 questions
50
votes
10 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
  • 13,357
  • 5
  • 63
  • 89
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
23
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
  • 7,922
  • 2
  • 47
  • 59
18
votes
3 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
  • 4,777
  • 1
  • 8
  • 24
16
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
  • 358
  • 1
  • 2
  • 8
16
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
  • 422
  • 3
  • 10
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,372
  • 1
  • 10
  • 18
14
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,157
  • 1
  • 13
  • 33
14
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,806
  • 1
  • 22
  • 49
11
votes
2 answers

Count the numer of instance 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
  • 8,944
  • 25
  • 89
  • 182
10
votes
2 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,449
  • 16
  • 25
10
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
  • 16,573
  • 4
  • 41
  • 66
9
votes
2 answers

JMESPath - parse raw string as object

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
  • 5,619
  • 3
  • 26
  • 31
9
votes
2 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"]?
xor
  • 3,583
  • 1
  • 21
  • 32
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
1
2 3
19 20