Re: xml-to-json() function under SaxonJS
Martin Honnen <[email protected]> Tue, 21 Sep 2021 17:30:09 +0200
| Newsgroups | gmane.text.xml.saxon.help |
|---|---|
| Organization | Liberty Development |
| Message-ID | <[email protected]> |
On 21.09.2021 16:12, Wendell Piez wrote:
> Today I am a bit surprised to find I get no luck, using SaxonJS in the
> browser, when trying to serialize JSON as anything but a data brick,
> when produced by the function xml-to-json(). It is supposed to accept
> $options and 'indent' is the option available, but unless I am missing
> something, map{ 'indent':true() } is not operative.
>
> The documentation says that the function json-to-xml() does not support
> $options but xml-to-json() is not mentioned. Can I confirm that it is
> (not) user error that is preventing me from getting the JSON indented,
> instead of prettified?
>
> If this is not supported what is the recommended workaround: perhaps a
> JSON serializer is not so hard to write? (I have not thought about it much.)
As a workaround, if you know your XSLT returns a JSON string to
JavaScript, I guess you could run it through JSON.stringify on the
JavaScript side:
JSON.stringify(JSON.parse(xsltResult), null, 2);
(where 2 is the number of indenting spaces you want).