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": [

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 
<>. (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 Makeig
Director, Product Management

> On Dec 1, 2016, at 9:55 AM, Gary Vidal <> wrote:
> All,
> Is there an equivalent to format json output like
>  declare option xdmp:output "indent=yes";
> _______________________________________________
> General mailing list
> Manage your subscription at: 

General mailing list
Manage your subscription at:

Reply via email to