Extract leaves from JSON file with JSONpath

后端 未结 1 1277
名媛妹妹
名媛妹妹 2021-01-25 20:52

I have a JSON output from an REST API and the output looks like this:

{
\"sprints\": [{
    \"id\": 10516,
    \"sequence\": 10516,
    \"name\": \"SP121 - BRK r         


        
相关标签:
1条回答
  • 2021-01-25 21:47

    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.

    0 讨论(0)
提交回复
热议问题