Changes

Jump to navigation Jump to search
240 bytes removed ,  18:31, 1 December 2023
m
Text replacement - "</syntaxhighlight>" to "</pre>"
let $json := json:parse($file)
return db:add($database, $json, $name)
</syntaxhighlightpre>
'''Example 2: Converts a simple JSON string to XML and back'''
<syntaxhighlight lang="xquery">
json:parse('{}')
</syntaxhighlightpre>
'''Result:'''
<syntaxhighlight lang="xml">
<json type="object"/>
</syntaxhighlightpre>
'''Query:'''
declare option output:method 'text';
json:serialize(<json type="object"/>)
</syntaxhighlightpre>
'''Result:'''
<syntaxhighlight lang="xquery">
{ }
</syntaxhighlightpre>
'''Example 3: Converts a JSON string with simple objects and arrays'''
"generator": "http://www.flickr.com/"
}')
</syntaxhighlightpre>
'''Result:'''
<generator>http://www.flickr.com/</generator>
</json>
</syntaxhighlightpre>
'''Example 4: Converts a JSON string with different data types'''
]
}', $options)
</syntaxhighlightpre>
'''Result:'''
</phone>
</json>
</syntaxhighlightpre>
==JsonML Format==
let $json := json:serialize($doc, map { 'format': 'jsonml' })
return file:write($name, $json)
</syntaxhighlightpre>
'''Example 2: Converts an XML document with elements and text'''
<syntaxhighlight lang="xquery">
json:serialize(doc('flickr.xml'), map { 'format': 'jsonml' })
</syntaxhighlightpre>
'''flickr.xml:'''
<generator>http://www.flickr.com/</generator>
</flickr>
</syntaxhighlightpre>
'''Result:'''
["generator",
"http://www.flickr.com/"]]
</syntaxhighlightpre>
'''Example 3: Converts a document with nested elements and attributes to JsonML'''
<syntaxhighlight lang="xquery">
json:serialize(doc('input.xml'), map { 'format': 'jsonml' })
</syntaxhighlightpre>
'''input.xml:'''
<phone type='home'>212 555-1234</phone>
</address>
</syntaxhighlightpre>
'''Result:'''
["phone", {"type":"home"},
"212 555-1234"]]
</syntaxhighlightpre>
==XQuery Format==
$k || ': ' || string-join($v, ', ')
})
</syntaxhighlightpre>
'''Result:'''
Author: Jim Daniels, Jack Beam
Title: Drinks
</syntaxhighlightpre>
'''Example 2: Converts XQuery data to JSON'''
map { 'format': 'xquery', 'indent': 'no' }
)
</syntaxhighlightpre>
'''Result:'''
[1,2,3,4,5]
{"Key":"Value"}
</syntaxhighlightpre>
=Errors=
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu