Kaz Kylheku <046…@kylheku.com> writes:
> On 2026-11-17, Anton Antimo <ant…@safunu.org> wrote:
>> Kaz Kylheku <046…@kylheku.com> writes: >>
>>> On 2026-11-16, Anton Antimo <ant…@safunu.org> wrote:
>>>> It seems cl-json is automatically escaping slashes when I invoke >>>> encode-json-to-string. I located the question >>>> >>>> https://stackoverflow.com/questions/60103909 >>>> >>>> that explains that the JSON spec mandates the escaping of slashes, but >>>> doesn't really explain why, although it says there's not quite a >>>> practical need for that. >>>> >>>> Do you know why the escaping of slashes was considered in the first place?
>>> >>> It allows JSON to be embedded into HTML. >>> >>> Consider JSON which looks like this: >>> >>> [ "</script>" ] // oops: false positive for end of script marker. >>> >>> [ "<\/script>" ] // no problem
>> >> Interesting. So the JSON spec was particularly thinking of HTML at its >> beginning? I never thought of JSON as too intimate of HTML, but perhaps >> it was meant for the web specifically. Thanks for the info.
> > JSON is based on Javascript (the "JS"). It's possible to interpolate > JSON as a literal into Javascript code, and that in turn can be embedded > in a web page.
I see---that's the HTML connection then. I guess it's been so successful that it's often taken out of the web now.
> JSON can also be stored somewhere in a HTML and accessed by JS code via > the DOM. For instance: > > <script type="application/json" id="prefs"> > { > "username": "John Smith", > "theme": "dark", > } > </script> > > Script elsewhere in that page just finds the app-settings node and > retrieves the JSON from it. > > const prefs_node = document.getElementById('prefs'); > const prefs = JSON.parse(prefs_node.textContent);
So cool! I never knew that. Thanks for showing.