Laterade Laterade - 4 months ago 8x
JSON Question

Updating JSON in XQuery and Marklogic 8

I've got a simple enough JSON document stored in Marklogic:

{ "title": "mytitle", "edition": "1" }

Is there a way I can add a new field using Xquery functions so my document and object end up looking is this?

{ "title": "mytitle", "edition": "1", "date": "2016-01-01" }

There apparently is support for JSON manipulation via xdmp:node-replace, xdmp:insert-child-after, etc found in the documentation here:

I have had 0 luck with the above. Any suggestions?

wst wst

When you only need to insert a property, you first have to wrap the property/value in an object-node, then select the property child:

  object-node { "date": "2016-01-01" }/date)