Created
June 1, 2020 08:52
-
-
Save ableasdale/35675988a15b75539712ace91d7890b6 to your computer and use it in GitHub Desktop.
MarkLogic: processing JSON using XPath
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "1.0-ml"; | |
(: Taken from: | |
https://www.linkedin.com/posts/kurtcagle_informatix8gulp-saxon-xslt-activity-6673109285721010176-hDYU/ | |
See also: | |
https://www.npmjs.com/package/@informatix8/gulp-saxon-xslt | |
The above example was modified from Kurt's example to work with MarkLogic Server. | |
:) | |
let $json := '[ | |
{"name":"Jane Doe","occupation":"Data Scientist","age":24}, | |
{"name":"George Keens","occupation":"Programmer","age":27}, | |
{"name":"Elaine Chou","occupation":"Manager","age":32}]' | |
let $records := xdmp:unquote($json) | |
let $avg-age := format-number(avg($records//age), '###.00') | |
return <div>The average age of all employees is <b>{$avg-age}</b>.</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment