all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Help with list of list object passed to json-encode
@ 2022-04-28  2:28 Kaushal Modi
  2022-05-29  8:43 ` Tim Landscheidt
  0 siblings, 1 reply; 2+ messages in thread
From: Kaushal Modi @ 2022-04-28  2:28 UTC (permalink / raw)
  To: Help Gnu Emacs mailing list

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Help with list of list object passed to json-encode
  2022-04-28  2:28 Help with list of list object passed to json-encode Kaushal Modi
@ 2022-05-29  8:43 ` Tim Landscheidt
  0 siblings, 0 replies; 2+ messages in thread
From: Tim Landscheidt @ 2022-05-29  8:43 UTC (permalink / raw)
  To: help-gnu-emacs

Kaushal Modi <kaushal.modi@gmail.com> wrote:

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

> […]

> 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?

Probably not.  An association list is just a list of cons
(and thus may also be a list of lists).  Whether to treat it
as a "simple" list or an association list just depends on
the function which the programmer calls on them, there is no
"association list type".  A vector on the other hand is a
different data type and can thus be discerned from (associa-
tion) lists.

Tim




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-29  8:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-28  2:28 Help with list of list object passed to json-encode Kaushal Modi
2022-05-29  8:43 ` Tim Landscheidt

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.