-
-
Save micheee/8a8734a1713a7121cab15eb3dfb389d9 to your computer and use it in GitHub Desktop.
parse-json.xq
This file contains 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
let $items := ( | |
fetch:text('https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json') | |
=> parse-json() (: Convert to XQuery item representation :) | |
=> array:for-each(function($map){ (: For each entry in that array, do :) | |
element item { (: Construct an XML element named item :) | |
$map => map:keys() | |
=> for-each(function($key){ (: For each key in the map, do: :) | |
element { $key } { (: Return an element named $key :) | |
$map($key) (: …and the value of $map($key) :) | |
} | |
}) | |
} | |
}) | |
=> array:flatten() (: Converts the array to a sequence :) | |
) | |
for $item in $items | |
return $item (: …insert node $item as last into … :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment