Re: xml-to-json() function under SaxonJS

Michael Kay <[email protected]> Tue, 21 Sep 2021 17:01:49 +0100
Newsgroups gmane.text.xml.saxon.help
Message-ID <[email protected]>
--===============6163539957500381413==
Content-Type: multipart/alternative;
	boundary="Apple-Mail=_57CA8196-5A9A-4083-85B4-771AD33920B6"


--Apple-Mail=_57CA8196-5A9A-4083-85B4-771AD33920B6
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii

Confirmed, we haven't implemented indent:yes in the JSON serializer in =
Saxon-JS.

Doing a nice indentation algorithm is actually quite tricky, and we like =
to keep the code small, but I guess doing a simple-minded indentation =
might be better than none at all. The main complication is deciding when =
it makes sense to put things on the same line, e.g.=20

{ "name": ["Michael", "Kay"],
  "company": "Saxonica"
}

It would be tempting to just generate the JSON and then call parse =3D> =
stringify, but that would almost certainly apply escaping rules that =
make the result non-conformant.

Michael Kay
Saxonica

> On 21 Sep 2021, at 15:12, Wendell Piez <[email protected]> wrote:
>=20
> Hello Saxonians,
>=20
> 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.
>=20
> 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?
>=20
> 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.)
>=20
> Thanks for any insight or advice,
> Wendell
>=20
> --=20
> ...Wendell Piez... ...wendell -at- nist -dot- gov...
> ...wendellpiez.com... ...pellucidliterature.org... =
...pausepress.org...
> ...github.com/wendellpiez. <http://github.com/wendellpiez.>.. =
...gitlab.coko.foundation/wendell...
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/saxon-help


--Apple-Mail=_57CA8196-5A9A-4083-85B4-771AD33920B6
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=us-ascii

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; =
charset=3Dus-ascii"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; line-break: after-white-space;" =
class=3D"">Confirmed, we haven't implemented indent:yes in the JSON =
serializer in Saxon-JS.<div class=3D""><br class=3D""></div><div =
class=3D"">Doing a nice indentation algorithm is actually quite tricky, =
and we like to keep the code small, but I guess doing a simple-minded =
indentation might be better than none at all. The main complication is =
deciding when it makes sense to put things on the same line, =
e.g.&nbsp;</div><div class=3D""><br class=3D""></div><div class=3D"">{ =
"name": ["Michael", "Kay"],</div><div class=3D"">&nbsp; "company": =
"Saxonica"</div><div class=3D"">}</div><div class=3D""><br =
class=3D""></div><div class=3D"">It would be tempting to just generate =
the JSON and then call parse =3D&gt; stringify, but that would almost =
certainly apply escaping rules that make the result =
non-conformant.</div><div class=3D""><br class=3D""></div><div =
class=3D"">Michael Kay</div><div class=3D"">Saxonica</div><div =
class=3D""><div><br class=3D""><blockquote type=3D"cite" class=3D""><div =
class=3D"">On 21 Sep 2021, at 15:12, Wendell Piez &lt;<a =
href=3D"mailto:[email protected]" =
class=3D"">[email protected]</a>&gt; wrote:</div><br =
class=3D"Apple-interchange-newline"><div class=3D""><div dir=3D"ltr" =
class=3D"">Hello Saxonians,<div class=3D""><br class=3D""></div><div =
class=3D"">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.</div><div =
class=3D""><br class=3D""></div><div class=3D"">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?</div><div class=3D""><br class=3D""></div><div class=3D"">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.)</div><div class=3D""><br class=3D""></div><div class=3D"">Thanks =
for any insight or advice,</div><div class=3D"">Wendell<br clear=3D"all" =
class=3D""><div class=3D""><br class=3D""></div>-- <br class=3D""><div =
dir=3D"ltr" class=3D"gmail_signature" =
data-smartmail=3D"gmail_signature">...Wendell Piez... ...wendell -at- =
nist -dot- gov...<br class=3D"">...<a href=3D"http://wendellpiez.com" =
class=3D"">wendellpiez.com</a>... ...<a =
href=3D"http://pellucidliterature.org" =
class=3D"">pellucidliterature.org</a>... ...<a =
href=3D"http://pausepress.org" class=3D"">pausepress.org</a>...<br =
class=3D"">...<a href=3D"http://github.com/wendellpiez." target=3D"_blank"=
 class=3D"">github.com/wendellpiez.</a>.. =
...gitlab.coko.foundation/wendell... </div></div></div>
_______________________________________________<br class=3D"">saxon-help =
mailing list archived at <a href=3D"http://saxon.markmail.org/" =
class=3D"">http://saxon.markmail.org/</a><br class=3D""><a =
href=3D"mailto:[email protected]" =
class=3D"">[email protected]</a><br =
class=3D"">https://lists.sourceforge.net/lists/listinfo/saxon-help =
</div></blockquote></div><br class=3D""></div></body></html>=

--Apple-Mail=_57CA8196-5A9A-4083-85B4-771AD33920B6--


--===============6163539957500381413==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============6163539957500381413==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[email protected]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
--===============6163539957500381413==--