<div dir="auto">What's really sad is I spent a lot of time getting the existing JSON working on the server side, with conversion to XML, Java and JavaScript.   I suspect that will have to be redone.   I need to include the GUI next time.   <div dir="auto"><br></div><div dir="auto">John</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Apr 27, 2017 6:22 AM, "Roy Walmsley" <<a href="mailto:roy.walmsley@ntlworld.com">roy.walmsley@ntlworld.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
The trick when considering translating from XML encoding to JSON encoding is to think of the what is needed in the middle, i.e. what is loaded into memory, or, equivalently, what would be displayed on the screen. So, considering the examples below one at a time:<br>
<br>
        X3D  "quote mark  \"  is &amp;quot;"<br>
<br>
I presume that the term X3D implies that we looking at an XML  encoding of a string. So, what we want to see on the screen is<br>
<br>
        quote mark " is &quot;<br>
<br>
The escaping rules for JSON are simple. An easy to understand diagram is at  <a href="http://www.json.org/" rel="noreferrer" target="_blank">http://www.json.org/</a>. So translating this memory representation to the JSON encoding gives:<br>
<br>
        "quote mark \" is &quot;"<br>
<br>
Notice that the ampersand shall not be escaped in the JSON encoding. In fact, only the quotation mark " and the reverse solidus \ have to be escaped. The escaping of the forward solidus / is optional.<br>
<br>
Now let's look at the second example.<br>
<br>
        JSON "empty string \\\\\"\\\\\" skips a line:",<br>
<br>
This is already a JSON encoding. So a parser will load this and display the following string<br>
<br>
        empty string \\"\\" skips a line:<br>
<br>
Clearly that is not what is desired. What you want to see is:<br>
<br>
        empty string "" skips a line:<br>
<br>
So, encoded into JSON this becomes<br>
<br>
        "empty string \"\" skips a line:"<br>
<br>
Similarly, encoded into the XML encoding gives<br>
<br>
        "empty string \"\" skips a line:"<br>
<br>
So yes, I would conclude that you are far too zealous in adding all those backslashes.<br>
<br>
Remember, you are not trying to write an XML encoded string as a JSON encoding. You are going via computer memory, where loading the XML encoding undoes all the escaping. You then only have to do the new escaping on the unescaped string.<br>
<br>
Hope this helps. Happy to talk if you want. Especially as I haven't involved stylesheets in the discussion above!<br>
<br>
All the best,<br>
<br>
Roy<br>
<br>
-----Original Message-----<br>
From: x3d-public [mailto:<a href="mailto:x3d-public-bounces@web3d.org">x3d-public-bounces@<wbr>web3d.org</a>] On Behalf Of Don Brutzman<br>
Sent: 27 April 2017 03:30<br>
To: John Carlson <<a href="mailto:yottzumm@gmail.com">yottzumm@gmail.com</a>><br>
Cc: <a href="mailto:x3d-public@web3d.org">x3d-public@web3d.org</a><br>
Subject: Re: [x3d-public] MFString quoting [was: interesting sample] JSON escaping example<br>
<br>
On 4/26/2017 4:02 PM, <a href="mailto:yottzumm@gmail.com">yottzumm@gmail.com</a> wrote:<br>
> I do have a problem with the JSON encoding for the attached file (translated by X3dToJson.xslt).  Let me know if you think otherwise.  Look at all the \\\\\.<br>
<br>
i suspect the issue is illustrated by the following SFString within an MFString<br>
<br>
        X3D  "quote mark  \"  is &amp;quot;"<br>
        JSON "empty string \\\\\"\\\\\" skips a line:",<br>
<br>
will try to break it down.<br>
<br>
double-backslash escaping going on here for JSON; so internal content-only correspondences should likely be<br>
<br>
        [X3D ]  \<br>
        [JSON]  \\<br>
<br>
        [X3D ]  "<br>
        [JSON]  \"<br>
<br>
        [X3D ]  \"<br>
        [JSON]  \\\"<br>
<br>
        [X3D ]  quote mark  \"  is &amp;quot;<br>
        [JSON]  quote mark \\\" is &quot;<br>
<br>
please count.  does that look right?<br>
<br>
if so, then it looks like the X3dToJson.xslt is overzealously prepending 2 extra backslashes in this particular case (one of several).<br>
<br>
if not, then please advise what the right answer is.<br>
<br>
also please re-advise, where are the JSON backslash-related rules?<br>
<br>
if we can agree on what the right answer looks like, then i will dive back into the independently XML/XSLT/XPath escaped (and obtw recursive) stylesheet template that consumes/produces this stuff to try doing the job correctly.  (gulp!)<br>
<br>
p.s. if anyone out there isn't dizzy yet, congrats!<br>
<br>
<br>
> Sent from Mail <<a href="https://go.microsoft.com/fwlink/?LinkId=550986" rel="noreferrer" target="_blank">https://go.microsoft.com/<wbr>fwlink/?LinkId=550986</a>> for Windows 10<br>
><br>
> *From: *Andreas Plesch <mailto:<a href="mailto:andreasplesch@gmail.com">andreasplesch@gmail.<wbr>com</a>><br>
> *Sent: *Wednesday, April 26, 2017 5:21 PM<br>
> *To: *John Carlson <mailto:<a href="mailto:yottzumm@gmail.com">yottzumm@gmail.com</a>><br>
> *Cc: *Don Brutzman <mailto:<a href="mailto:brutzman@nps.edu">brutzman@nps.edu</a>>; X3D Graphics public mailing list <mailto:<a href="mailto:x3d-public@web3d.org">x3d-public@web3d.org</a>><br>
> *Subject: *Re: [x3d-public] MFString quoting [was: interesting sample]<br>
><br>
> On Wed, Apr 26, 2017 at 3:55 PM, <<a href="mailto:yottzumm@gmail.com">yottzumm@gmail.com</a> <mailto:<a href="mailto:yottzumm@gmail.com">yottzumm@gmail.com</a>>> wrote:<br>
><br>
>     It’s<br>
><br>
>     <a href="http://x3dgraphics.com/slidesets/X3dForWebAuthors/Chapter02GeometryPrimitives.pdf" rel="noreferrer" target="_blank">http://x3dgraphics.com/<wbr>slidesets/X3dForWebAuthors/<wbr>Chapter02GeometryPrimitives.<wbr>pdf</a><br>
><br>
>     Got caught in the grand renaming.  Also the parent page is wrong.<br>
><br>
> Thanks.<br>
all the best, Don<br>
--<br>
Don Brutzman  Naval Postgraduate School, Code USW/Br       <a href="mailto:brutzman@nps.edu">brutzman@nps.edu</a><br>
Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   <a href="tel:%2B1.831.656.2149" value="+18316562149">+1.831.656.2149</a><br>
X3D graphics, virtual worlds, navy robotics <a href="http://faculty.nps.edu/brutzman" rel="noreferrer" target="_blank">http://faculty.nps.edu/<wbr>brutzman</a><br>
<br>
______________________________<wbr>_________________<br>
x3d-public mailing list<br>
<a href="mailto:x3d-public@web3d.org">x3d-public@web3d.org</a><br>
<a href="http://web3d.org/mailman/listinfo/x3d-public_web3d.org" rel="noreferrer" target="_blank">http://web3d.org/mailman/<wbr>listinfo/x3d-public_web3d.org</a><br>
<br>
</blockquote></div></div>