Reputation: 61
How to get each field of json doc in XQUERY Marklogic?
let $doc :=
{
"field1" :'t',
"field2" : 'th',
"filed4": 'the'
}
return
$doc//??,
{
"New Filed" : "Added"
}
So how can we get the output like below ?
{ "field1" :'t', "field2" : 'th', "filed4": 'the' ,"New Filed" : "Added"}
Upvotes: 1
Views: 163
Reputation: 66714
A JSON object is really just a specialized map. So you can use map operators, like the +
union operator:
let $doc := object-node
{
"field1" :'t',
"field2" : 'th',
"filed4": 'the'
}
return
$doc + map:entry("NewField", "added")
Upvotes: 0
Reputation: 7335
One approach: use the xdmp:from-json()
to convert the immutable JSON node to a mutable map and then set the field:
return xdmp:from-json($doc) => map:with("NewField", "Added")
For more detail, see: https://docs.marklogic.com/xdmp:from-json
Hoping that helps,
Upvotes: 1