1

I'm pretty new to XPath... I need to extract only the values 2124,143 from this JSON array using XPath.

I tried few ways but didn't succeed. Any idea?

{  
       "legend_size":1,
       "data":{  
          "series":[  
             "2016-06-01",
             "2016-07-01"
          ],
          "values":{  
             "Download":{  
                "2016-07-01":143,
                "2016-06-01":2124
             }
          }
       }
    }

2 Answers 2

1

XPath (traditionally, prior to v3.1, which is not widely supported) is defined over XML, not JSON.

Alternatively, consider JSONPath, an "XPath for JSON," which is also supported by Dojo Toolkit.

In JSONPath, 2124 could be accessed as $.data.values.Download.2016-06-01

Sign up to request clarification or add additional context in comments.

Comments

0

In XPath 3.1, it would be

let $j := parse-json($input)
return array:for-each($j?data?series,
   function($date) {$j?data?values($date)})

XPath 3.1 is the first version of XPath to support JSON as well as XML.

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.