Hi Florent, You are effectively passing an unnamed (root) object-node with a single property as argument, whereas the node function is expecting the (named) property itself. In XQuery you would append /text() after your JSON to fix that:
xdmp:node-insert-child(doc("/test.json")/object-node(), object-node{ "c": "d" }/text()) But I don¹t think that will work in JS.. On the other hand, why don¹t you convert the JSON node to a real JS JSON object, manipulate that in the old fashion JS way, and insert that back into the db? Might be much more practical, particularly if you are making multiple changes.. Cheers On 5/18/16, 9:13 AM, "general-boun...@developer.marklogic.com on behalf of Florent Georges" <general-boun...@developer.marklogic.com on behalf of li...@fgeorges.org> wrote: >Hi, > >I am sure I am missing something simple here... I am trying to add an >object node to a JSON doc stored in the database using JavaScript. >But all examples and documentation I can find are about either JavaScript >manipulating XML nodes, or XQuery manipulating JSON documents. > >Especially, in XQuery, one can use object-node {} to construct an object >node. Which in turn can be used with e.g. xdmp:node-insert-child(). >But if I try the following in JavaScript: > > xdmp.nodeInsertChild( > fn.doc(uri).next().value.root.foo, > { three: [ 'tres', 3, 'trois' ] }); > >then I get the following error: > > [javascript] XDMP-CHILDUNNAMED: xdmp.nodeInsertChild( > fn.head(xdmp.unpath("fn:doc('...')/foo")), > {"three":["tres", 3, "trois"]}) > -- Object nodes cannot have unnamed children > >Any idea what (quite obvious I presume) I am missing? > >Regards, > >-- >Florent Georges >http://fgeorges.org/ >http://h2oconsulting.be/ >_______________________________________________ >General mailing list >General@developer.marklogic.com >Manage your subscription at: >http://developer.marklogic.com/mailman/listinfo/general _______________________________________________ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general