Hi Florent, Looks odd indeed. If you wrap the fn.doc result in json, it serializes as string, but if you refer to the result of fn.doc directly, it produces json basic xml. Keep in mind though that fn.doc is likely returning a MarkLogic json object node type (wrapped in a ValueIterator), which you are nesting directly into a plain JS json object. The transform function gets thrown off because of this, probably..
A workaround is to use toObject() upfront: fn.doc('/test/one.json').next().value.toObject() Or slightly shorter: cts.doc('/test/one.json').toObject() That way you will embed plain JSON into plain JSON.. Cheers, Geert On 4/6/16, 12:37 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 trying to use json:transform-from-json(), and I get a weird >result on JSON object nodes retrieved from the database. The >following script produces the expected result: > >var j = require('/MarkLogic/json/json'); >var obj = {'objects': [{'obj':{'id':'one'}},{'obj':{'id':'two'}}]}; >j.transformFromJson(obj); > >But if I change the array in the object to retrieve both objects from >the database: > >var j = require('/MarkLogic/json/json'); >var obj = {'objects': [fn.doc('/test/one.json'), >fn.doc('/test/two.json')]}; >j.transformFromJson(obj); > >Then it serializes them both as strings: > ><json type="object" xmlns="http://marklogic.com/xdmp/json/basic"> > <objects type="array"> > <item type="string">{"obj":{"id":"one"}}</item> > <item type="string">{"obj":{"id":"two"}}</item> > </objects> ></json> > >The following query inserts both documents: > >declareUpdate(); >xdmp.documentInsert('/test/one.json', { 'obj': {'id': 'one'} }); >xdmp.documentInsert('/test/two.json', { 'obj': {'id': 'two'} }); > >I thought fn.doc() would return the object nodes, not a string >representing them. Did I miss anything? > >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