Subject: bug#42733: 27.1; json-serialize doesn't not encode list like json-encode

From: Philipp <[email-masked]>
Date: Mon, 5 Jul 2021 19:45:19 +0200

> Am 12.06.2021 um 14:53 schrieb Lars Ingebrigtsen <[email-masked]>:
> 
> Jimmy Yuen Ho Wong <[email-masked]> writes:
> 
>> (json-encode '("foo" "bar"))
>> => "[\"foo\",\"bar\"]"
>> 
>> (json-serialize '("foo" "bar"))
>> 
>> Debugger entered--Lisp error: (wrong-type-argument symbolp "foo")
>>  json-serialize(("foo" "bar"))
>> 
>> The potential for people to naively substitute json-encode with
>> json-serialize and breaking their code is enormous. This is already
>> happening in lsp-mode. Please make json-serialize behave like
>> json-encode.
> 
> json.c is a lot less "DWIM" than json.el -- which I think is generally a
> good idea when it comes to doing round-trips between Elisp and JSON,
> because you avoid a lot of corner cases.
> 
> So I'd be inclined to just regard this as a feature, but I've added
> Philipp to the CCs -- perhaps he has some comments.

What Lars said.  In general, DWIM can be a good choice for high-level user-facing commands, but not for lower-level library functions like this.  Second-guessing the intention of the caller often generates surprising or subtly wrong results, which isn't what you want for interpreting a rather low-level protocol like JSON.  json-serialize thus very intentionally behaves differently than the json.el functions.