Article View: comp.lang.lisp
Article #53Re: on cl-json and slashes
From: Anton Antimo
Date: Wed, 18 Nov 2026 13:30
Date: Wed, 18 Nov 2026 13:30
53 lines
3092 bytes
3092 bytes
Kaz Kylheku <046-301-5902@kylheku.com> writes:
> On 2026-11-17, Anton Antimo <anton@safunu.org> wrote:
>> Kaz Kylheku <046-301-5902@kylheku.com> writes:
>>
>>> On 2026-11-16, Anton Antimo <anton@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.
Technical Details
Message-ID:
<87o6bme07c.fsf@safunu.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<87jymcbkom.fsf@safunu.org> <20261116165945.535@kylheku.com> <87mrr7ljt8.fsf@safunu.org> <20261117073624.759@kylheku.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Anton Antimo <anton@safunu.org> Newsgroups: comp.lang.lisp Subject: Re: on cl-json and slashes Date: Wed, 18 Nov 2026 10:30:31 -0300 Organization: A noiseless patient Spider Lines: 53 Message-ID: <87o6bme07c.fsf@safunu.org> References: <87jymcbkom.fsf@safunu.org> <20261116165945.535@kylheku.com> <87mrr7ljt8.fsf@safunu.org> <20261117073624.759@kylheku.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Wed, 18 Nov 2026 15:00:21 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1521713"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+DMt88N2yIBYcivXjnO11N33/Zxr2Gjk4="; posting-host="66020d2047509dc3afab3f6af4afe7e3" Cancel-Lock: sha1:0Ndp61QqPDLKpexfTMJBp6VjmLM= sha1:H/0JHOKt6O9lKlOWUBHNTcT2EGs= sha256:iJu+s1GgxvRlGhQkKX5HXQqGIDGr4hAB8yBrhKJvWgg= sha1:JyvR7c7An+eycorr47ZtNmX5ThY= sha256:LTdDh6VC7IVypYgOnNEoFOs+xADK+g1K9LitWBAoa14=