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
137
votes
6 answers

How to 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.
  • 6,451
  • 9
  • 36
  • 36
103
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
  • 2,187
  • 6
  • 22
  • 38
78
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,894
  • 7
  • 34
  • 61
43
votes
5 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
  • 4,105
  • 4
  • 32
  • 46
41
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
  • 4,004
  • 3
  • 36
  • 59
40
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
  • 776
  • 1
  • 7
  • 10
37
votes
6 answers

AWS step functions and optional parameters

I would like to have a default value for a parameter passed into a step function e.g., "Parameters": { "foo.$": "$.foo" OR "bar" if "$.foo" not specified } is there a way to do this natively with JSONPath or do I have to use a choice + pass…
wrschneider
  • 17,913
  • 16
  • 96
  • 176
37
votes
5 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
  • 2,215
  • 3
  • 17
  • 26
34
votes
4 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
  • 30,567
  • 53
  • 217
  • 400
34
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
  • 28,994
  • 18
  • 176
  • 206
32
votes
4 answers

Asserting array of arrays with JSONPath and spring mvc

I'm having difficulty figuring out how to assert with jsonPath in a JSON document response in spring mvc. Perhaps there's a better way of accomplishing this than using jsonPath for this particular scenario. I would like to validate that the links…
Magnus Lassi
  • 921
  • 2
  • 9
  • 21
28
votes
3 answers

How do I extract multiple values from kubectl with jsonpath

I've found jsonpath examples for testing multiple values but not extracting multiple values. I want to get image and name from kubectl get pods. this gets me name kubectl get pods -o=jsonpath='{.items[*].spec.containers[*].name}' | xargs -n…
navicore
  • 1,979
  • 4
  • 34
  • 50
26
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
  • 385
  • 1
  • 4
  • 8
26
votes
1 answer

select multiple attributes with jsonpath

I have an array of objects like this one: [ { "id": 192, "name": "Complete name", "username": "nsurname", "state": "active", "created_at": "2016-05-30T07:09:40.981Z", "organization": "", …
mnieto
  • 3,744
  • 4
  • 21
  • 37
25
votes
2 answers

How to save content of a configmap to a file with kubectl and jsonpath?

I'm trying to save the contents of a configmap to a file on my local hard drive. Kubectl supports selecting with JSONPath but I can't find the expression I need to select just the file contents. The configmap was created using the command kubectl…
PeterH
  • 801
  • 2
  • 7
  • 16
1
2 3
99 100