Extract leaves from JSON file with JSONpath

匆匆过客 提交于 2019-12-02 12:27:33
tobi6

Testing on jsonpath.com with the query $.velocityStatEntries. you showed in the question results in data which could be mapped:

'0' ...
  '10123' ...
    'estimated' ...
      'value' => "11.5"
      'text' => "11.5"
    'completed' ...
      'value' => "5.5"
      'text' => "5.5"
  '10182' ...
    'estimated' ...
      'value' => "12"
      'text' => "12.0"
    'completed' ...
      'value' => "10"
      'text' => "10.0"
  '10183' ...
    'estimated' ...
      'value' => "12"
      'text' => "12.0"
    'completed' ...
      'value' => "7"
      'text' => "7.0"

Testing the same source data with the query you showed in the comments $.velocityStatEntries[*] results in no data to map:

'0' ...
  'estimated' ...
    'value' => "11.5"
    'text' => "11.5"
  'completed' ...
    'value' => "5.5"
    'text' => "5.5"
'1' ...
  'estimated' ...
    'value' => "12"
    'text' => "12.0"
  'completed' ...
    'value' => "10"
    'text' => "10.0"
'2' ...
  'estimated' ...
    'value' => "12"
    'text' => "12.0"
  'completed' ...
    'value' => "7"
    'text' => "7.0"

I suggest checking your query again and using the first one.

EDIT

You seem very close. After more information is available I suggest you check the query $.velocityStatEntries and extract the fields [0], estimated.value and completed.value.

I am not too sure about the [0] (I have suggested this with a little different JSON schema here). This is because JSONPath does not work well with elements which are IDs for themselves. XMLPath can't interpret this at all, so you might check my other answer for further reference in how to gather data from element descriptors which are IDs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!