26

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?

3
  • 1
    What do you want to parse it into? Language? Commented Feb 15, 2012 at 10:22
  • I want to know the JSONPATH e.g. $.* to get any item of the array. Commented Feb 15, 2012 at 13:18
  • So you want to use JSONPath, whose implementations for several languages are available at code.google.com/p/json-path and goessner.net/articles/JsonPath Commented Feb 15, 2012 at 14:47

3 Answers 3

50

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]
Sign up to request clarification or add additional context in comments.

Comments

0

Using DefiantJS, you can search a JSON structure with XPath syntax. This library extends the global object JSON with a search function.

In this scenario, you can write something like this;

var data = [
  [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]
],
search = JSON.search( data, '//*/*/*' );

Check out this fiddle; http://jsfiddle.net/hbi99/5NfeM/

Comments

0

This works for me

JsonPath.with(jsonResponse).param("name", "getName").get("findAll { a -> a.name == name  }")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.