Hi E. Wray,
Can you give an example of how to convert JSON data to atomic XQuery items (sepecifically strings, numbers and booleans)?
Sure:
let $options := map { 'format': 'map' } for $json in ( '"string"', '1984', 'true' ) return json:parse($json, $options)
With BaseX 9.0, you’ll need to change 'map' to 'xquery'. You can also use fn:parse-json without second argument (see [1] for more examples).
Cheers, Christian
[1] https://www.w3.org/TR/xpath-functions-31/#func-parse-json
On Wed, Nov 15, 2017 at 6:26 PM, E. Wray Johnson wray.johnson@gmail.com wrote:
Christian,
Can you give an example of how to convert JSON data to atomic XQuery items (sepecifically strings, numbers and booleans)? Is it as simple as removing the curly brackets to bound an object?
On Wed, Nov 15, 2017 at 11:05 AM, Kendall Shaw kendall.shaw@workday.com wrote:
On 11/15/17, 4:24 AM, "basex-talk-bounces@mailman.uni-konstanz.de on behalf of Christian Grün" <basex-talk-bounces@mailman.uni-konstanz.de on behalf of christian.gruen@gmail.com> wrote:
Hi Maurice, Depending on the chosen format, different outputs will be generated by json:parse. Traditionally, it is true that only XML was generated by this function, but in newer versions (and in alignment with the XQuery 3.1 specs and the fn:parse-json function), it is also possible now to convert JSON data to atomic XQuery items (maps, arrays, strings, numbers and booleans) [1,2]. The resulting representation will be more memory-efficient, and access to XQuery maps is blazing fast, but it won’t be possible to store this representation to a database. Hope this helps, greetings, Christian [1]
https://urldefense.proofpoint.com/v2/url?u=http-3A__docs.basex.org_wiki_JSON... [2] https://urldefense.proofpoint.com/v2/url?u=http-3A__docs.basex.org_wiki_JSON...
On Wed, Nov 15, 2017 at 8:30 AM, <m.vankeulen@utwente.nl> wrote: > Christian, > > The JSON Module suggests that JSON objects are represented as
XML-documents > with a certain structure, not as immutable maps. Is there support in BaseX > for json:parse and json:serialize for parsing JSON in textual form into > immutable maps and back to JSON in textual form? > > Kind regards, > Maurice van Keulen
Aside from XQuery and BaseX converting JSON, because JSON is not just objects, I think there could be a problem with the concept of converting JSON to maps, also. For example, these JSON documents aren’t map-like:
- true
- ["a", "a", "a", "x"]
Kendall