Parse JSON array file with JSONPATH

Kheiri picture Kheiri · Feb 15, 2012 · Viewed 57.5k times · Source

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?

Answer

ArjunShankar picture ArjunShankar · Feb 15, 2012

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]