This is fixed/improved in 8.0.3 The json:config object expects the values to be sequence not an array. Your code is passing an array value which isnt automatically converted to a sequence.
You can convert the array to a sequence with xdmp.arrayValues() like this: custom['array-element-names'] = xdmp.arrayValues(['foo', 'bar']) ----------------------------------------------------------------------------- David Lee Lead Engineer MarkLogic Corporation [email protected] Phone: +1 812-482-5224 Cell: +1 812-630-7622 www.marklogic.com<http://www.marklogic.com/> From: [email protected] [mailto:[email protected]] On Behalf Of Peter Swartwout Sent: Monday, June 08, 2015 3:13 PM To: [email protected] Subject: [MarkLogic Dev General] Using custom json:config from javascript Hello all, I'm trying out the server-side javascript in ML 8. My company stores all of its content in XML format. We access it using REST from javascript UIs, so it's convenient to deliver search results as JSON. I know I can do this with XQuery, but I'd like to see if it's even possible in Javascript first. First of all, please verify my assumption that there is no native way in javascript to configure a custom transformation from xml to json. Since there isn't, I'm using code like this: var xqueryJson = require("/MarkLogic/json/json"); var config = xqueryJson.config("custom"); config.whitespace = "ignore"; ... etc ... This works, but there are some gotchas. For example, I can configure an array element name like so: config["array-element-names"] = "results" and it works, XML elements named "results" are transformed into an array in json. But it won't do more than one. For example: // This has no effect. How to do multiple array elements? var arrayNames = []; arrayNames.push("results"); arrayNames.push("matches"); config["array-element-names"] = arrayNames; Is it possible in javascript to configure more than one array element name?
_______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
