🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.lisp
Article #49

Re: on cl-json and slashes

#49
From: Kaz Kylheku
Date: Tue, 17 Nov 2026 16:44
51 lines
2905 bytes
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.

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);

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
Technical Details
Message-ID: <20261117073624.759@kylheku.com>
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
References: <87jymcbkom.fsf@safunu.org> <20261116165945.535@kylheku.com> <87mrr7ljt8.fsf@safunu.org>

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: Kaz Kylheku <046-301-5902@kylheku.com>
Newsgroups: comp.lang.lisp
Subject: Re: on cl-json and slashes
Date: Tue, 17 Nov 2026 16:44:46 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <20261117073624.759@kylheku.com>
References: <87jymcbkom.fsf@safunu.org> <20261116165945.535@kylheku.com>
 <87mrr7ljt8.fsf@safunu.org>
Injection-Date: Tue, 17 Nov 2026 16:44:47 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="639666"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19EwVDgJJbQi23bq5D6ydFxz79MmzkSbyU="; posting-host="2ea98194fc4e1764e93d015a3b02c220"
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:+PQxaj6Q8WdDPuk/im5LBmltGXc= sha256:0T12wMYtpapn6Gze3PxTf6FmSOZ2XrV+2O2T5XKHuZU=
	sha1:AjxtRPArW2F7jf1iHiLRhtboas0= sha256:H18VseDUGYhh9AKFGdmkPxLRdu3AnO0R4O6x4RlNaf0=