Re: xml-to-json() function under SaxonJS
Wendell Piez <[email protected]> Wed, 22 Sep 2021 13:11:46 -0400
| Newsgroups | gmane.text.xml.saxon.help |
|---|---|
| Message-ID | <CAAO_-xxbE8ZC9VN+mYhWQ97LpSua99_EPpsOeavC77PvEXA+KA@mail.gmail.com> |
--===============6407468321818761614== Content-Type: multipart/alternative; boundary="0000000000006bff4b05cc989cbd" --0000000000006bff4b05cc989cbd Content-Type: text/plain; charset="UTF-8" Hi again, Today I write just to double check the same question on the serialize() function, and where at the top of the page at /conformance/xslt30 it says it does not implement the serialization spec, I should take that to mean I am my own also with formatting serialized XML on the page? I can live with this (indeed it gives me some control I would like -- I try to look at the bright side of things) but again I wanted to make sure I am not missing anything. Thanks, Wendell On Tue, Sep 21, 2021 at 3:02 PM Wendell Piez <[email protected]> wrote: > 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... > -- ...Wendell Piez... ...wendell -at- nist -dot- gov... ...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org... ...github.com/wendellpiez... ...gitlab.coko.foundation/wendell... --0000000000006bff4b05cc989cbd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Hi again,<div><br></div><div>Today I write just to double = check the same question on the serialize() function, and where at the top o= f the page at /conformance/xslt30 it says it does not implement the seriali= zation spec, I should take that to mean I am my own also with formatting se= rialized XML on the page?</div><div><br></div><div>I can live with this (in= deed it gives me some control I would like -- I try to look at the bright s= ide of things) but again I wanted to make sure I am not missing anything.</= div><div><br></div><div>Thanks,</div><div>Wendell</div><div><br></div><div>= <br></div><div><br></div></div><br><div class=3D"gmail_quote"><div dir=3D"l= tr" class=3D"gmail_attr">On Tue, Sep 21, 2021 at 3:02 PM Wendell Piez <<= a href=3D"mailto:[email protected]">[email protected]</a>> wro= te:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px = 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"= ltr">Hello Mike and Martin,<div><br></div><div>Thank you for confirming thi= s. It's the escaping even more than the indentation that worries me.</d= iv><div><br></div><div>In my experience, there is no set of whitespace rule= s that everyone will agree is ideal or even very nice. But it is also not s= o difficult to=C2=A0do better than the brick.</div><div><br></div><div>I wi= ll definitely look at that XSLT (in the spec). I could perhaps use Javascri= pt .stringify except I would like to inject the raw JSON for display into t= he page, which is so easy to do in SaxonJS. Indeed, in this case I am afrai= d the 'right way' is to do it in XSLT. A variant could produce mark= up for syntax coloring.</div><div><br></div><div>Thanks, Wendell</div><div>= <br></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gm= ail_attr">On Tue, Sep 21, 2021 at 12:02 PM Michael Kay <<a href=3D"mailt= o:[email protected]" target=3D"_blank">[email protected]</a>> = wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0= px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Conf= irmed, we haven't implemented indent:yes in the JSON serializer in Saxo= n-JS.<div><br></div><div>Doing a nice indentation algorithm is actually qui= te tricky, and we like to keep the code small, but I guess doing a simple-m= inded indentation might be better than none at all. The main complication i= s deciding when it makes sense to put things on the same line, e.g.=C2=A0</= div><div><br></div><div>{ "name": ["Michael", "Kay= "],</div><div>=C2=A0 "company": "Saxonica"</div><d= iv>}</div><div><br></div><div>It would be tempting to just generate the JSO= N and then call parse =3D> stringify, but that would almost certainly ap= ply escaping rules that make the result non-conformant.</div><div><br></div= ><div>Michael Kay</div><div>Saxonica</div><div><div><br><blockquote type=3D= "cite"><div>On 21 Sep 2021, at 15:12, Wendell Piez <<a href=3D"mailto:wa= [email protected]" target=3D"_blank">[email protected]</a>> wrot= e:</div><br><div><div dir=3D"ltr">Hello Saxonians,<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 but a data brick, when produced b= y the function xml-to-json(). It is supposed to accept $options and 'in= dent' is the option available, but unless I am missing something, map{ = 'indent':true() } is not operative.</div><div><br></div><div>The do= cumentation 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 err= or that is preventing me from getting the JSON indented, instead of prettif= ied?</div><div><br></div><div>If this is not supported what is the recommen= ded 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"all"><div><br></div>-- <br><div d= ir=3D"ltr">...Wendell Piez... ...wendell -at- nist -dot- gov...<br>...<a hr= ef=3D"http://wendellpiez.com" target=3D"_blank">wendellpiez.com</a>... ...<= a href=3D"http://pellucidliterature.org" target=3D"_blank">pellucidliteratu= re.org</a>... ...<a href=3D"http://pausepress.org" target=3D"_blank">pausep= ress.org</a>...<br>...<a href=3D"http://github.com/wendellpiez." target=3D"= _blank">github.com/wendellpiez.</a>.. ...gitlab.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">...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/wen= dellpiez.</a>.. ...gitlab.coko.foundation/wendell... </div> </blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"= class=3D"gmail_signature">...Wendell Piez... ...wendell -at- nist -dot- go= v...<br>...wendellpiez.com... ...pellucidliterature.org... ...pausepress.or= g...<br>...<a href=3D"http://github.com/wendellpiez." target=3D"_blank">git= hub.com/wendellpiez.</a>.. ...gitlab.coko.foundation/wendell... </div> --0000000000006bff4b05cc989cbd-- --===============6407468321818761614== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --===============6407468321818761614== 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 --===============6407468321818761614==--