简体   繁体   中英

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: https://docs.marklogic.com/guide/app-dev/json#id_60123

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

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:

xdmp:node-insert-child(
  doc('/mydoc.json')/node(),
  object-node { "date": "2016-01-01" }/date)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM