Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse JSON array file with JSONPATH

Tags:

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?

like image 845
Kheiri Avatar asked Feb 15 '12 10:02

Kheiri


People also ask

How get values from JsonPath?

We can use JsonPath in Rest Assured to extract value. This is done with the help of the jsonPath method (which is a part of the JsonPath class). After that, we need to use the get method and pass the key that we want to obtain from the JSON Response.

What is the difference between JSON and JsonPath?

JSONPath creates a uniform standard and syntax to define different parts of a JSON document. JSONPath defines expressions to traverse through a JSON document to reach to a subset of the JSON. This topic is best understood by seeing it in action. We have created a web page which can help you evaluate a JSONPath.

What is the output of JsonPath method?

3.3. JsonPath also has functions that we can use at the end of a path to synthesize that path's output expressions: min(), max(), avg(), stddev() and length(). Finally, we have filters. These are boolean expressions to restrict returned lists of nodes to only those that calling methods need.


1 Answers

If the object is:

[   [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] ] 

Then "$[0]" will return:

[50.4154134372953,-1.28486558931069,"CLASS B",9,205,0,"UK",431500382,3,4] 

And "$[1]" will return:

[50.3058858494047,-0.976070494820637,"CLASS B",9,239,0,"UK",2750350,21,2] 

You can do it two levels deep as well. "$[0][4]" will return:

205 

You can also extract the elements of the array into a list with "$[*]", which will return a list of 2 elements. The first being:

[50.4154134372953,-1.28486558931069,"CLASS B",9,205,0,"UK",431500382,3,4] 

and the second being:

[50.3058858494047,-0.976070494820637,"CLASS B",9,239,0,"UK",2750350,21,2] 
like image 160
ArjunShankar Avatar answered Sep 25 '22 07:09

ArjunShankar