[MarkLogic Dev General] ML8 Json

Justin Makeig Justin.Makeig at marklogic.com
Mon Mar 23 14:52:59 PDT 2015

You're constructing XML and trying to insert an object-node child. That's not allowed in MarkLogic 8. Previously xdmp:to-json returned a string, as there was no object-node type. In MarkLogic 8 we introduced new node types to represent JSON: object-node, array-node, null-node, boolean-node, and number-node. (JSON strings share text node types with their XML brethren.) In order to get the serialized string you should use xdmp:quote, as you suggest.


Justin Makeig
Director, Product Management
jmakeig at marklogic.com

> On Mar 23, 2015, at 2:45 PM, Paul Williams <Paul.Williams at flatironssolutions.com> wrote:
> In upgrading from ML6 to ML8 we have an issue in our application code where we are generating JSON for a client-side script.  I know there has been a huge change in JSON support, but can anyone tell me exactly what is going on here?
> Sample code:
> xquery version "1.0-ml";
> let $obj :=
>        <json:object xmlns:json="http://marklogic.com/xdmp/json">
>        <json:entry><json:key>name</json:key><json:value xsi:type="xs:string">world</json:value></json:entry>
>        <json:entry><json:key>label</json:key><json:value xsi:type="xs:string">hello</json:value></json:entry>
>        </json:object>
> let $doc := xdmp:to-json(json:object($obj))
> return
>        <script type="text/javascript">var obj = {$doc}</script>
> If you execute that in ML6, as expected, you get…
>                 <script type="text/javascript">var obj = {"name":"world", "label":"hello"}</script>
> But in ML8, you get this error pointing at the highlighted reference
>                 XDMP-CHILDNODEKIND: $doc -- element nodes cannot have object node children
> I’m not sure exactly what is the “element node” this message refers to.  I know that I can quote the reference (xdmp:quote($doc)) and make it work, but I’m trying to understand what specifically is different between ML6 & ML8 that is causing this problem so I can be sure of my workaround. 
> Any comments?
> Paul Williams | Technical Consultant
> M: +1 402 203 2232 | Sk: paul.wms
> Paul.Williams at FlatironsSolutions.com <mailto:Paul.Williams at FlatironsSolutions.com>
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20150323/653ad341/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4477 bytes
Desc: not available
Url : http://developer.marklogic.com/pipermail/general/attachments/20150323/653ad341/attachment.bin 

More information about the General mailing list