GNU bug report logs - #42733
27.1; json-serialize doesn't not encode list like json-encode

Previous Next

Package: emacs;

Reported by: Jimmy Yuen Ho Wong <wyuenho <at> gmail.com>

Date: Thu, 6 Aug 2020 22:18:02 UTC

Severity: normal

Tags: moreinfo, notabug

Found in version 27.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Philipp <p.stephani2 <at> gmail.com>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 42733 <at> debbugs.gnu.org, Philipp Stephani <phst <at> google.com>, Jimmy Yuen Ho Wong <wyuenho <at> gmail.com>
Subject: bug#42733: 27.1; json-serialize doesn't not encode list like json-encode
Date: Mon, 5 Jul 2021 19:45:19 +0200

> Am 12.06.2021 um 14:53 schrieb Lars Ingebrigtsen <larsi <at> gnus.org>:
> 
> Jimmy Yuen Ho Wong <wyuenho <at> gmail.com> 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.



This bug report was last modified 3 years and 322 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.