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
25
votes
1 answer

Extracting a subset of attributes with JSONPath

I have this JSON code: { "A": { "AB": [{ "ABA": "0", "ABB": "1", "ABC": "2" }] } } I need to use a JSONPath expression that returns that JSON with only ABA and ABC attributes. Something…
Spaffo
  • 621
  • 2
  • 8
  • 12
25
votes
5 answers

Basic use of JSONPath in Java

I have JSON as a string and a JSONPath as a string. I'd like to query the JSON with the JSON path, getting the resulting JSON as a string. I gather that Jayway's json-path is the standard. The online API, however, doesn't have have much relation to…
Cannoliopsida
  • 3,044
  • 5
  • 36
  • 61
25
votes
4 answers

How to list object key names with jsonpath?

I am using nodejs with jsonpath. I have this json structure: { things:{ books: [ {name: "book1"}, {name: "book2"}, {name: "book3"}, {name: "book4"}, ], movies: [ {name: "movie1"}, {name: "movie2"}, …
norteo
  • 1,828
  • 2
  • 13
  • 7
25
votes
4 answers

JSON.NET how to remove nodes

I have a json like the following: { "d": { "results": [ { "__metadata": { }, "prop1": "value1", "prop2": "value2", "__some": "value" }, { "__metadata": { }, …
Mohamed Nuur
  • 5,536
  • 6
  • 39
  • 55
23
votes
4 answers

How to change values in a json file using XPath/JsonPath in java

here is the json file { "session": { "name":"JSESSIONID", "value":"5864FD56A1F84D5B0233E641B5D63B52" }, "loginInfo": { "loginCount":77, …
vaibhavcool20
  • 861
  • 3
  • 11
  • 28
22
votes
2 answers

Get keys in JSON

I get the following JSON result from an external system: { "key1": "val1", "key2": "val2", "key3": "val3" } Now I want to display all keys and all values by using JSONPath. So I am looking for something to get key1, key2 and key3 as a result.…
Stefan
  • 1,253
  • 2
  • 12
  • 36
22
votes
1 answer

Trouble composing jsonpath query to return first object of a filtered array

Using the ashphy json path evaluator, and the following JSON: { "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category":…
Blazes
  • 4,721
  • 2
  • 22
  • 29
22
votes
4 answers

Hamcrest with MockMvc: check that key exists but value may be null

I'm doing some tests with MockMvc, and I want to validate the structure of a JSON response. Specifically, I want to make sure that the key to an attribute exists, and that the value is of a certain type or null. { "keyToNull": null, # This may…
nebulabrot
  • 465
  • 1
  • 6
  • 13
21
votes
6 answers

Kubernetes / kubectl print all secrets

I would like to use kubectl to print out all key-value pairs in my Secrets. I cannot figure out how to do this in one line with the -o --jsonpath flag or by piping into jq. I could certainly make a script to do this but I feel there must be a better…
s g
  • 5,289
  • 10
  • 49
  • 82
20
votes
4 answers

How to use C# example using JsonPath?

I'm trying to use JsonPath for .NET (http://code.google.com/p/jsonpath/downloads/list) and I'm having trouble finding an example of how to parse a Json string and a JsonPath string and get a result. Has anyone used this?
Niels Bosma
  • 11,758
  • 29
  • 89
  • 148
20
votes
1 answer

kubectl: Use custom-columns output with maps

I want to get the specific value of an annotation into a kubectl custom columns field. I can get all the current annotations on a resource like so: kubectl get pvc -o custom-columns=NAME:.metadata.name,"ANNOTATIONS":.metadata.annotations -n…
jaxxstorm
  • 12,422
  • 5
  • 57
  • 67
20
votes
4 answers

JSONPath Syntax when dot in key

Please forgive me if I use the incorrect terminology, I am quite the novice. I have some simple JSON: { "properties": { "footer.navigationLinks": { "group": "layout" , "default": [ { "text": "Link a" …
Hayley
  • 221
  • 1
  • 2
  • 7
19
votes
2 answers

JsonPath : filter by value in array

I'm trying to filter by value an array in my Json with Jsonpath. I want to get the long_name of the country in the JSON below. In order to do that, I filter the adress_components by types[0] == "country" but it doesn't seem to work. The JsonPath I…
ShenM
  • 193
  • 1
  • 1
  • 4
19
votes
4 answers

How to extract keys in a nested json array object in Presto?

I'm using the latest(0.117) Presto and trying to execute CROSS JOIN UNNEST with complex JSON array like this. [{"id": 1, "value":"xxx"}, {"id":2, "value":"yy"}, ...] To do that, first I tried to make an ARRAY with the values of id by SELECT…
k-kawa
  • 1,289
  • 2
  • 11
  • 18
19
votes
1 answer

Find object in nested data by property value (with JSONPath)

I have this test data: [ { id: 1, l: 'a', sub: [ ] }, { id: 2, l: 'b', sub: [ { id: 4, l: 'd' }, { id: 5, l: 'e' }, { id: 6, l: 'f', …
alexandernst
  • 14,352
  • 22
  • 97
  • 197