Questions tagged [jsonpath]

JSONPath is a means of using XPath-like syntax to query JSON structures. Not to be confused with rest-assured's JsonPath implementation based on Groovy's Gpath. Use the [json-path-expression] tag for questions about JSON path expressions in general and for questions about JSON path expression DSLs.

JSONPath is a means of using XPath-like syntax to query JSON structures.

It is not a standard, but it does offer a means of querying JavaScript structures directly without needing to convert to or from XML.
JSONPath expressions always refer to a JSON structure in the same way as XPath expression are used in combination with an XML document.

Implementations:

Not to be confused with the standard of the same name by rest-assured: https://github.com/rest-assured/rest-assured/wiki/Usage#json-using-jsonpath

1786 questions
14
votes
3 answers

How to find last element in Array list using jsonpath expression?

I have json string like below [ { "topic": "inputTopic", "key": "0", "message": "test", "partition": 0, "offset": 0 }, { "topic": "inputTopic", "key": "0", "message":…
Pradeep Poojari
  • 155
  • 1
  • 1
  • 9
13
votes
2 answers

how to Validate if JSON Path Exists in JSON

In a given json document, how to validate if a json path exists ? I am using jayway-jsonpath and have the below code JsonPath.read(jsonDocument, jsonPath) The above code can potentially throw below…
Vinod Jayachandran
  • 3,726
  • 8
  • 51
  • 88
13
votes
6 answers

Possible to search case-insensitive with JSONPath?

Using the SelectToken method of JSON.NET to select a token with JSONPath, I found no way to specifiy that the search should be case-insensitive. E.g. json.SelectToken("$.maxAppVersion") should return a matching token, no matter whether it is…
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
13
votes
4 answers

Matching data in JsonPath with wiremock

I'm trying to create mocks for my login procedure. I use POST method with a couple of fields and login object (with login, password, etc.) For that I'm using JsonPath. Code below: { "request": { "method": "POST", "url": "/login", …
a_dzik
  • 927
  • 2
  • 11
  • 24
13
votes
1 answer

Gatling - Looping through JSON array

I have a block of code which needs to loop through a JSON array which is obtained from response of a REST service. (Full gist available here.) .exec(http("Request_1") .post("/endPoint") .headers(headers_1) …
Neil
  • 5,919
  • 15
  • 58
  • 85
13
votes
3 answers

JsonPath - read Java Long type

I've got JSON data that looks like this {"sessionID":7242750700467747000} The number is previously obtained from server response and is generated server-side as Java Long. Client identifies itself thought this sessionID and sends it with requests.…
Wojtek
  • 2,514
  • 5
  • 26
  • 31
12
votes
4 answers

Check output of JsonPath with Hamcrest Matchers

I wrote Spring controller Junits. I used JsonPath to fetch all IDs from JSON using ["$..id"]. I have following as test method : mockMvc.perform(get(baseURL + "/{Id}/info", ID).session(session)) .andExpect(status().isOk()) // Success …
SuhasD
  • 728
  • 2
  • 7
  • 20
12
votes
2 answers

Pick the Nth item from a filter expression in JSONPath

I've been trying to filter a specific element in my JSON using JSONPath and then to choose only the 1st item in the returned array of results. My baisc JSONPath looks something like this: $.store.book[?(@.category==fiction)].price I want to add…
Roy_ro
  • 123
  • 1
  • 4
12
votes
1 answer

Select attribute name with JsonPath

I'm consuming a JSON feed that returns a structure with an array of irregular objects - I can't predict what's in the array, and whatever is there will change over time. A simple example is { "content": [ { "person" : "john" …
Shukri Adams
  • 851
  • 1
  • 12
  • 30
11
votes
2 answers

How do I get a list of all JSON paths to values from a JSON String?

My goal is to read a JSON file and understand the location of all the values, so that when I encounter that same JSON, I can easily read all the values. I am looking for a way to return a list containing all of the paths to each data value, in…
yak
  • 481
  • 1
  • 4
  • 8
11
votes
1 answer

Is there a way to get substring of a string value in JSONPath?

Basically, I need to get a part of the string value using JSONPath. I cannot get the full value using JSONPath first and then get the part of it using another language. Is there any way to do it in JSONPath?
Leon
  • 1,011
  • 1
  • 11
  • 28
11
votes
7 answers

JSONPath Query to get Node-names?

Consider the following piece of JSONPath: { "result":[ { "type":"Residence", "street":"Piazza di Spagna", "city":"-4:0" }, { "type":"Residence", "street":"test", …
Larry
  • 11,439
  • 15
  • 61
  • 84
10
votes
3 answers

Print keys in yaml, so that they can be used for jsonpath

echo "apiVersion: v1 kind: Node metadata: name: host-cluster-control-plane-64j47 labels: beta.kubernetes.io/arch: amd64 " | yq -o p Result: apiVersion = v1 kind = Node metadata.name =…
guettli
  • 25,042
  • 81
  • 346
  • 663
10
votes
3 answers

How can I summarize all the resource limits and requests in Kubernetes with kubectl?

I started using Lens and noticed that it gives you some warnings when the pods inside the nodes have limits higher than the actual capacity. So I tried to get this information with kubectl but I'm new to jsonpath and I just managed to get the raw…
jmservera
  • 6,454
  • 2
  • 32
  • 45
10
votes
2 answers

JSONPath expression to get a value from an array on condition or just the first value

Given JSON structured like this: { "name":"Some Guy", "emails":[ { "description":"primary", "status":"UNVERIFIED", "email":"first@first-email.com" }, { "description":"home", …
jhericks
  • 5,833
  • 6
  • 40
  • 60