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

1303 questions
111
votes
5 answers

count members with jsonpath?

Is it possible to count the number of members using JsonPath? Using spring mvc test I'm testing a controller that generates {"foo": "oof", "bar": "rab"} with standaloneSetup(new FooController(fooService)).build() …
NA.
  • 5,891
  • 7
  • 33
  • 36
80
votes
5 answers

How to test if JSON path does not include a specific element, or if the element is present it is null?

I have been writing some simple unit testing routines for a simple spring web application. When I add @JsonIgnore annotation on a getter method of a resource, the resulting json object does not include the corresponding json element. So when my unit…
Zobayer Hasan
  • 1,719
  • 3
  • 19
  • 34
57
votes
5 answers

How to filter by string in JSONPath?

I have a JSON response from the Facebook API that looks like this: { "data": [ { "name": "Barack Obama", "category": "Politician", "id": "6815841748" }, { "name": "Barack Obama's Dead Fly", …
Alastair
  • 5,220
  • 6
  • 30
  • 55
31
votes
4 answers

Getting a single value from a JSON object using JSONPath

I have the following JSON and I need to get the plain name value using JSONPath: { "single" : { "id" : 1, "name" : "Item name" } } Expression that I used is $.single.name but I always get an array: [ "Item name" ] instead of a string…
Ilija
  • 3,630
  • 4
  • 30
  • 45
29
votes
2 answers

SpringMVC/ mockMVC/ jsonpath compare list of strings

I am currently writing some unit tests for a Spring MVC project. As the returned media type is JSON, I try to use jsonPath to check if the correct values are returned. The trouble I have is to verify if a list of strings contains the correct (and…
Martin Keßler
  • 551
  • 1
  • 5
  • 9
27
votes
3 answers

How to use MockMvcResultMatchers.jsonPath

MvcResult result = this.mockMvc.perform( MockMvcRequestBuilders.get(mockUrl)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentType("application/ …
Pradeep Vairamani
  • 3,299
  • 2
  • 30
  • 52
26
votes
2 answers

Array size using jsonpath expression - Stefan Goessner JsonPath

I'm having a problem with finding an array or list size using Stefan Goessner's JsonPath. I'm using the version json-path-2.0.0. My jsonpath expression is $.orders.length and JSON looks something like this: { "orders" : [ ... ] } Its…
Nagendra Varma
  • 1,846
  • 3
  • 15
  • 24
23
votes
1 answer

JSON.NET JObject - how do I get value from this nested JSON structure

I have this JSON: { "client_id": "26075235", "client_version": "1.0.0", "event": "app.uninstall", "timestamp": 1478741247, "data": { "user_id": "62581379", "site_id": "837771289247593785", …
Chris Halcrow
  • 21,541
  • 11
  • 115
  • 145
23
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
  • 591
  • 2
  • 5
  • 12
23
votes
4 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
  • 2,779
  • 4
  • 29
  • 61
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,405
  • 2
  • 19
  • 28
21
votes
3 answers

Parse JSON array file with JSONPATH

I want to parse this with JSONPath: [ [50.4154134372953,-1.28486558931069,"CLASS B",9,205,0,"UK",431500382,3,4], [50.3058858494047,-0.976070494820637,"CLASS B",9,239,0,"UK",2750350,21,2] ] Can you help with that please?
Kheiri
  • 335
  • 1
  • 2
  • 7
20
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,648
  • 2
  • 11
  • 7
20
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,056
  • 6
  • 34
  • 52
19
votes
3 answers

How to concatenate constant string with jsonpath

I have AWS step machine and one of the step is used to notify failure using SNS service. I want to select some metadata from input json into outgoing message. So i am trying to concatenate constant string with jsonpath like below "Notify Failure":…
LP13
  • 20,711
  • 38
  • 136
  • 286
1
2 3
86 87