I want to add a new key-value pair to JSON created using object-node constructor.
Object node:
object-node {
"status": "success",
"categories": "cat"
}
XQuery code to insert new pair:
let $outputJson :=
object-node {
"status": "success",
"categories": "cat"
}
return ( map:put($outputJson, "str", "xyz"), $outputJson )
The above expression fails. Is there a way to insert a new pair?
It is annoying that the
object-node()
can't be manipulated as you might expect, but theobject-node()
is not mutable.Instead use
json:object()
, which will provide a specialized mutable map: