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

Native way to run a forEach loop on an unnamed JSON object

Example JSON [ { "id": 12, "clientName": "super-client" }, { "id": 15, "clientName": "helloClient" } ] I want to use JMESPath to check if each clientName field does not contain the text super- and then display the result I'm…
Shads
  • 33
  • 2
3
votes
2 answers

How to project list of lists using JMESPath?

Suppose I have the json: [ [0, "a"], [1, "b"], [2, "c"] ] How can I create a JMESPath projection to get: [ {"id": 0, "name": "a"}, {"id": 1, "name": "b"}, {"id": 2, "name": "c"} ]
jack
  • 147
  • 1
  • 7
3
votes
2 answers

Grafana Generic OAuth Role Assignment

I am trying to integrate Keycloak as OAuth provider for Grafana. I am successful in authenticating the user but not able to assign the correct role to the user. Following are the configurations that I have used. Grafana Environment Variable: -…
3
votes
0 answers

In JMESPath is there a way to return a list of dynamic keys based on condition of child key value pair

Based on the JSON the below I would like to return a list of the enabled account numbers using something like [?enabled == 'true'] with output like [11111, 33333]. Since the account numbers aren't stored in a key value pair is this possible? { …
atg
  • 31
  • 1
3
votes
1 answer

query key from complex json by combining dict2items and JMESPath with ansible

I'm looking to return value based on query result, so far I'm not getting the desired result. json looks like this and is coming from ansible var { "header": { "nodes": { "node1": { "last_shutdown": "date", …
JavaAllDay
  • 53
  • 1
  • 5
3
votes
1 answer

A query to get a JSON element on an object with JMESPATH

When I have a simple JSON like: { "name": "Tom", "age": 20 } Is there any JMESPath query to get age only when name is Tom? The query should get 20 with the upper JSON. But, if the name is not Tom like: { "name": "Bob", "age":…
Atsushi Sakai
  • 938
  • 10
  • 22
3
votes
1 answer

Ansible Filter with_items list

I am using Ansible 2.10.7 and I need to filter a specific item in the with_items list. Before using with_items msg looks like this: "ansible_facts": { "cvp_info": { "version": "2020.2.3" }, "devices": [ { …
Batchen Regev
  • 685
  • 1
  • 7
  • 28
3
votes
1 answer

How to match a regex on an array name itself in jmespath (json element string regex wildcard)

How can I search for an array in a json using a regex in jmespath? Consider the following JSON document (set aside if it's poorly constructed): { "people_in_town": [ {"letter": "a"}, {"letter": "b"}, ], "people_with_shoes": [ …
Michael Altfield
  • 2,083
  • 23
  • 39
3
votes
2 answers

Combine attribute value using json_query in ansible

I want to combine two attribute into single string separated by delimiter using the json_query in ansible Sample data { "locations": [ {"name": "Seattle", "state": "WA"}, {"name": "New York", "state": "NY"}, {"name": "Bellevue",…
Snkini
  • 571
  • 1
  • 5
  • 16
3
votes
1 answer

JMESPath how to write a query with multi-level filter?

I have been studying official documentation of JMESPath and a few other resources. However I was not successful with the following task: my data structure is a json from vimeo api (video list): data array contains lots of objects, each object is the…
Binuralka
  • 33
  • 6
3
votes
1 answer

JMESPath join output and strip unwanted chars

I have the following json; [ { "compartment-id": "CompartmentID-123", "defined-tags": {}, "display-name": "Test-123", "freeform-tags": {}, "id": "ID-ABC", "kms-key-id": "", "lifecycle-state": "ACTIVE", } ] I am…
CiCa
  • 141
  • 2
  • 13
3
votes
0 answers

is there a way to get the full path of a result in a jmespath query?

As an example, I have this json { "machines": [ {"name": "a", "state": "running"}, {"name": "b", "state": "stopped"}, {"name": "b", "state": "running"} ] } and my query is machines[?state=='stopped'].name which gives the result of…
KKS
  • 458
  • 5
  • 10
3
votes
2 answers

AWS CLI Find All Security Groups which Contain a Rule Allowing All Traffic from All Sources

Found some similar questions on here but none that specifically answered this question. I have several security groups that have rules that allow all traffic from all source IPs. I would like to concoct a simple CLI command that grabs these for…
3
votes
1 answer

Filter list based on another query result with JMESPath

Having an object such as the one below: { "pick": "a", "elements": [ {"id": "a", "label": "First"}, {"id": "b", "label": "Second"} ] } how can I retrieve the item in the elements list where id is equal to the value of pick? I was…
Victor
  • 13,914
  • 19
  • 78
  • 147
3
votes
3 answers

JMESPath to generate an array of objects from an object of objects

I have the following example json document (object of objects): { "key1": { "key1a": [{"key1aa": "value1aa"}, {"key1ab": "value1ab"}],... }, "key2": { "key2a": [{"key2aa": "value2aa"}, {"key2ab": "value2ab"}],... }, ... } And I try to…
David
  • 51
  • 1
  • 5