unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Kaushal Modi <kaushal.modi@gmail.com>
To: Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Help with list of list object passed to json-encode
Date: Wed, 27 Apr 2022 22:28:58 -0400	[thread overview]
Message-ID: <CAFyQvY03dVbdNosWaswpjXKZBQ0Jc+Y6PnbFqzJYoqWDs47JzA@mail.gmail.com> (raw)

Hello,

I was experimenting with passing different s-exp objects to
json-encode, and realized that this fails:

(json-encode '((foo . ((1 2) (3 4 5)))))


=====
Debugger entered--Lisp error: (json-key-format 1)
  signal(json-key-format (1))
  (or (json--print-stringlike object) (signal 'json-key-format (list object)))
  json--print-key(1)
  json--print-pair(1 (2))
  #f(compiled-function (pair) #<bytecode 0x5209ab54774c382>)((1 2))
  mapc(#f(compiled-function (pair) #<bytecode 0x5209ab54774c382>) ((1
2) (3 4 5)))
  #f(compiled-function #'map #<bytecode
-0x18b5c7332ae7fea>)(json--print-pair ((1 2) (3 4 5)))
  apply(#f(compiled-function #'map #<bytecode -0x18b5c7332ae7fea>)
json--print-pair ((1 2) (3 4 5)) nil)
  map-do(json--print-pair ((1 2) (3 4 5)))
  (let ((json--print-indentation-prefix (if json-encoding-pretty-print
json--print-indentation-prefix "")) (json--print-keyval-separator (if
json-encoding-pretty-print ": " ":")) (json--print-indentation-depth
(1+ json--print-indentation-depth))) (map-do #'json--print-pair map)
(delete-char (- (length json-encoding-separator))))
  (if (map-empty-p map) nil (let ((json--print-indentation-prefix (if
json-encoding-pretty-print json--print-indentation-prefix ""))
(json--print-keyval-separator (if json-encoding-pretty-print ": "
":")) (json--print-indentation-depth (1+
json--print-indentation-depth))) (map-do #'json--print-pair map)
(delete-char (- (length json-encoding-separator)))) (or
json-encoding-lisp-style-closings (json--print-indentation)))
  json--print-map(((1 2) (3 4 5)))
  json--print-alist(((1 2) (3 4 5)))
  (cond ((json-alist-p list) (json--print-alist list)) ((json-plist-p
list) (json--print-unordered-map list)) ((listp list)
(json--print-array list)) ((signal 'json-error (list list))))
  json--print-list(((1 2) (3 4 5)))
  (cond ((json--print-keyword object)) ((listp object)
(json--print-list object)) ((json--print-stringlike object)) ((numberp
object) (prin1 object)) ((arrayp object) (json--print-array object))
((hash-table-p object) (json--print-unordered-map object)) ((signal
'json-error (list object))))
  json--print(((1 2) (3 4 5)))
  json--print-pair(foo ((1 2) (3 4 5)))
=====

But this passes:

(json-encode '((foo . [(1 2) (3 4 5)])))

I'd like to understand why it's so.. Or is this a bug?

Thanks!


--
Kaushal Modi



             reply	other threads:[~2022-04-28  2:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-28  2:28 Kaushal Modi [this message]
2022-05-29  8:43 ` Help with list of list object passed to json-encode Tim Landscheidt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFyQvY03dVbdNosWaswpjXKZBQ0Jc+Y6PnbFqzJYoqWDs47JzA@mail.gmail.com \
    --to=kaushal.modi@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).