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

Wendell Piez <[email protected]> Tue, 21 Sep 2021 15:02:24 -0400
Newsgroups gmane.text.xml.saxon.help
Message-ID <CAAO_-xxan8Tehcx1-1A-jiQOYwreG=dkT8RcaxYxPc6DRh_8Jw@mail.gmail.com>
--===============5954839054022233533==
Content-Type: multipart/alternative; boundary="0000000000003f441405cc860a5a"

--0000000000003f441405cc860a5a
Content-Type: text/plain; charset="UTF-8"

Hello Mike and Martin,

Thank you for confirming this. It's the escaping even more than the
indentation that worries me.

In my experience, there is no set of whitespace rules that everyone will
agree is ideal or even very nice. But it is also not so difficult to do
better than the brick.

I will definitely look at that XSLT (in the spec). I could perhaps use
Javascript .stringify except I would like to inject the raw JSON for
display into the page, which is so easy to do in SaxonJS. Indeed, in this
case I am afraid the 'right way' is to do it in XSLT. A variant could
produce markup for syntax coloring.

Thanks, Wendell


On Tue, Sep 21, 2021 at 12:02 PM Michael Kay <[email protected]> wrote:

> 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.
>
> { "name": ["Michael", "Kay"],
>   "company": "Saxonica"
> }
>
> It would be tempting to just generate the JSON and then call parse =>
> 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:
>
> Hello Saxonians,
>
> 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.)
>
> Thanks for any insight or advice,
> Wendell
>
> --
> ...Wendell Piez... ...wendell -at- nist -dot- gov...
> ...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org...
> ...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
>
>
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/saxon-help



-- 
...Wendell Piez... ...wendell -at- nist -dot- gov...
...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org...
...github.com/wendellpiez... ...gitlab.coko.foundation/wendell...

--0000000000003f441405cc860a5a
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hello Mike and Martin,<div><br></div><div>Thank you for co=
nfirming this. It&#39;s the escaping even more than the indentation that wo=
rries me.</div><div><br></div><div>In my experience, there is no set of whi=
tespace rules that everyone will agree is ideal or even very nice. But it i=
s also not so difficult to=C2=A0do better than the brick.</div><div><br></d=
iv><div>I will definitely look at that XSLT (in the spec). I could perhaps =
use Javascript .stringify except I would like to inject the raw JSON for di=
splay into the page, which is so easy to do in SaxonJS. Indeed, in this cas=
e I am afraid the &#39;right way&#39; is to do it in XSLT. A variant could =
produce markup for syntax coloring.</div><div><br></div><div>Thanks, Wendel=
l</div><div><br></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr"=
 class=3D"gmail_attr">On Tue, Sep 21, 2021 at 12:02 PM Michael Kay &lt;<a h=
ref=3D"mailto:[email protected]">[email protected]</a>&gt; wrote:=
<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8=
ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style=3D"o=
verflow-wrap: break-word;">Confirmed, we haven&#39;t implemented indent:yes=
 in the JSON serializer in Saxon-JS.<div><br></div><div>Doing a nice indent=
ation algorithm is actually quite tricky, and we like to keep the code smal=
l, 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.=C2=A0</div><div><br></div><div>{ &quot;name&quot;: =
[&quot;Michael&quot;, &quot;Kay&quot;],</div><div>=C2=A0 &quot;company&quot=
;: &quot;Saxonica&quot;</div><div>}</div><div><br></div><div>It would be te=
mpting 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><br></div><div>Michael Kay</div><div>Saxonica</div><d=
iv><div><br><blockquote type=3D"cite"><div>On 21 Sep 2021, at 15:12, Wendel=
l Piez &lt;<a href=3D"mailto:[email protected]" target=3D"_blank">wapi=
[email protected]</a>&gt; wrote:</div><br><div><div dir=3D"ltr">Hello Saxo=
nians,<div><br></div><div>Today I am a bit surprised to find I get no luck,=
 using SaxonJS in the browser, when trying to serialize JSON as anything bu=
t a data brick, when produced by the function xml-to-json(). It is supposed=
 to accept $options and &#39;indent&#39; is the option available, but unles=
s I am missing something, map{ &#39;indent&#39;:true() } is not operative.<=
/div><div><br></div><div>The documentation says that the function json-to-x=
ml() does not support $options but xml-to-json() is not mentioned. Can I co=
nfirm that it is (not) user error that is preventing me from getting the JS=
ON indented, instead of prettified?</div><div><br></div><div>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><br></=
div><div>Thanks for any insight or advice,</div><div>Wendell<br clear=3D"al=
l"><div><br></div>-- <br><div dir=3D"ltr">...Wendell Piez... ...wendell -at=
- nist -dot- gov...<br>...<a href=3D"http://wendellpiez.com" target=3D"_bla=
nk">wendellpiez.com</a>... ...<a href=3D"http://pellucidliterature.org" tar=
get=3D"_blank">pellucidliterature.org</a>... ...<a href=3D"http://pausepres=
s.org" target=3D"_blank">pausepress.org</a>...<br>...<a href=3D"http://gith=
ub.com/wendellpiez." target=3D"_blank">github.com/wendellpiez.</a>.. ...git=
lab.coko.foundation/wendell... </div></div></div>
_______________________________________________<br>saxon-help mailing list =
archived at <a href=3D"http://saxon.markmail.org/" target=3D"_blank">http:/=
/saxon.markmail.org/</a><br><a href=3D"mailto:[email protected]=
net" target=3D"_blank">[email protected]</a><br><a href=3D"h=
ttps://lists.sourceforge.net/lists/listinfo/saxon-help" target=3D"_blank">h=
ttps://lists.sourceforge.net/lists/listinfo/saxon-help</a> </div></blockquo=
te></div><br></div></div>_______________________________________________<br=
>
saxon-help mailing list archived at <a href=3D"http://saxon.markmail.org/" =
rel=3D"noreferrer" target=3D"_blank">http://saxon.markmail.org/</a><br>
<a href=3D"mailto:[email protected]" target=3D"_blank">saxon=
[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/saxon-help" rel=3D"=
noreferrer" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo/=
saxon-help</a> </blockquote></div><br clear=3D"all"><div><br></div>-- <br><=
div dir=3D"ltr" class=3D"gmail_signature">...Wendell Piez... ...wendell -at=
- nist -dot- gov...<br>...wendellpiez.com... ...pellucidliterature.org... .=
..pausepress.org...<br>...<a href=3D"http://github.com/wendellpiez." target=
=3D"_blank">github.com/wendellpiez.</a>.. ...gitlab.coko.foundation/wendell=
... </div>

--0000000000003f441405cc860a5a--


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


--===============5954839054022233533==
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 
--===============5954839054022233533==--