Gary, I hope all is well with you.

Currently xdmp:output doesn't affect JSON nodes. It should. I'll add a Request 
For Enhancement (RFE) on my end to track this.

Here's a potential workaround:


(: See security guidance below :)
declare function json:stringify($json as node(), $spaces as xs:int) as 
xs:string? {
  xdmp:javascript-eval("JSON.stringify($json.toObject(), null, $spaces)", 
('$json', $json, '$spaces', $spaces))
};

declare function json:stringify($json as node()) as xs:string? {
  json:stringify($json, 2)
};

let $node := xdmp:unquote('["B", "B"]')
let $node := <asdf/> (: returns empty-sequence() :)
let $node := xdmp:unquote('{"a": "A", "b": ["B", "B"]}')
return json:stringify($node)

=> 

{
  "a": "A",
  "b": [
    "B",
    "B"
  ]
}

It uses xdmp:javascript-eval, which is potentially unsafe. You'd want to amp 
the json:stringify in a real production implementation so the eval can only be 
called in the context of json:stringify. See 
<https://docs.marklogic.com/guide/admin/security#id_81246>. (Note that 
JSON.stringify is *not* unsafe because it doesn't execute arbitrary 
JavaScript.) I haven't throughly tested the edge cases, but you get the idea.

Justin

--
Justin Makeig
Director, Product Management
MarkLogic
jmak...@marklogic.com

> On Dec 1, 2016, at 9:55 AM, Gary Vidal <gvidalsass...@gmail.com> wrote:
> 
> All,
> 
> Is there an equivalent to format json output like
>  declare option xdmp:output "indent=yes";
> _______________________________________________
> 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

Reply via email to