* JSON Parsing Edge Case
@ 2018-05-10 23:48 T.V Raman
2018-05-10 23:56 ` Noam Postavsky
0 siblings, 1 reply; 4+ messages in thread
From: T.V Raman @ 2018-05-10 23:48 UTC (permalink / raw)
To: emacs-devel
The following happens with both json-read -- the elisp implementation
as well as json-parse-string implemented in C --
Try this json fragment -- by typing it into an empty buffer:
{"quote": "1"}
The above is a json dict with one key -- "quote" -- with value 1.
Parsing this into an emacs alist -- either with (json-read) or
(json-parse-buffer)
yields the following lisp structure --
('. "1")
the list structure is really
(quote . "1")
but the elisp reader has turned that symbol "quote" into an "'"
--
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: JSON Parsing Edge Case
2018-05-10 23:48 JSON Parsing Edge Case T.V Raman
@ 2018-05-10 23:56 ` Noam Postavsky
2018-05-11 2:30 ` T.V Raman
0 siblings, 1 reply; 4+ messages in thread
From: Noam Postavsky @ 2018-05-10 23:56 UTC (permalink / raw)
To: T.V Raman; +Cc: Emacs developers
On 10 May 2018 at 19:48, T.V Raman <raman@google.com> wrote:
> The following happens with both json-read -- the elisp implementation
> as well as json-parse-string implemented in C --
>
> Try this json fragment -- by typing it into an empty buffer:
>
> {"quote": "1"}
>
> The above is a json dict with one key -- "quote" -- with value 1.
>
> Parsing this into an emacs alist -- either with (json-read) or
> (json-parse-buffer)
> yields the following lisp structure --
>
> ('. "1")
With json-read, and (json-read-from-string "{\"quote\": \"1\"}"), I get
((quote . "1"))
json-parse-string and json-parse-buffer don't seem to exist for me
(using the latest master branch).
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: JSON Parsing Edge Case
2018-05-10 23:56 ` Noam Postavsky
@ 2018-05-11 2:30 ` T.V Raman
2018-05-11 8:45 ` Basil L. Contovounesios
0 siblings, 1 reply; 4+ messages in thread
From: T.V Raman @ 2018-05-11 2:30 UTC (permalink / raw)
To: Noam Postavsky; +Cc: Emacs developers
Noam Postavsky <npostavs@gmail.com> writes:
I meant json-read-string --apologies. json-parse-buffer needs the
underlying emacs to be compiled with the json C module.
> On 10 May 2018 at 19:48, T.V Raman <raman@google.com> wrote:
>> The following happens with both json-read -- the elisp implementation
>> as well as json-parse-string implemented in C --
>>
>> Try this json fragment -- by typing it into an empty buffer:
>>
>> {"quote": "1"}
>>
>> The above is a json dict with one key -- "quote" -- with value 1.
>>
>> Parsing this into an emacs alist -- either with (json-read) or
>> (json-parse-buffer)
>> yields the following lisp structure --
>>
>> ('. "1")
>
> With json-read, and (json-read-from-string "{\"quote\": \"1\"}"), I get
>
> ((quote . "1"))
>
> json-parse-string and json-parse-buffer don't seem to exist for me
> (using the latest master branch).
>
--
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: JSON Parsing Edge Case
2018-05-11 2:30 ` T.V Raman
@ 2018-05-11 8:45 ` Basil L. Contovounesios
0 siblings, 0 replies; 4+ messages in thread
From: Basil L. Contovounesios @ 2018-05-11 8:45 UTC (permalink / raw)
To: T.V Raman; +Cc: Noam Postavsky, Emacs developers
"T.V Raman" <raman@google.com> writes:
> Noam Postavsky <npostavs@gmail.com> writes:
>
> I meant json-read-string --apologies. json-parse-buffer needs the
> underlying emacs to be compiled with the json C module.
>> On 10 May 2018 at 19:48, T.V Raman <raman@google.com> wrote:
>>> The following happens with both json-read -- the elisp implementation
>>> as well as json-parse-string implemented in C --
>>>
>>> Try this json fragment -- by typing it into an empty buffer:
>>>
>>> {"quote": "1"}
>>>
>>> The above is a json dict with one key -- "quote" -- with value 1.
>>>
>>> Parsing this into an emacs alist -- either with (json-read) or
>>> (json-parse-buffer)
>>> yields the following lisp structure --
>>>
>>> ('. "1")
>>
>> With json-read, and (json-read-from-string "{\"quote\": \"1\"}"), I get
>>
>> ((quote . "1"))
>>
>> json-parse-string and json-parse-buffer don't seem to exist for me
>> (using the latest master branch).
>>
FWIW, after emacs -Q and (require 'json), the following four forms all
evaluate to ((quote . "1")) on my end:
(with-temp-buffer
(insert "{\"quote\": \"1\"}")
(goto-char (point-min))
(json-read))
(with-temp-buffer
(insert "{\"quote\": \"1\"}")
(goto-char (point-min))
(json-parse-buffer :object-type 'alist))
(json-read-from-string "{\"quote\": \"1\"}")
(json-parse-string "{\"quote\": \"1\"}" :object-type 'alist)
AFAICT the json.el function json-read-string is for reading a single
JSON string at point, not a whole object.
--
Basil
In GNU Emacs 27.0.50 (build 20, x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
of 2018-05-10 built on thunk
Repository revision: 766b057e41df7316808ec7658836fda75facda75
Windowing system distributor 'The X.Org Foundation', version 11.0.11906000
System Description: Debian GNU/Linux buster/sid
Configured using:
'configure 'CC=ccache gcc' 'CFLAGS=-march=native -O2 -pipe'
--config-cache --prefix=/home/blc/.local --with-mailutils
--with-x-toolkit=lucid --with-modules --with-file-notification=yes
--with-x'
Configured features:
XAW3D XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS
NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS LUCID X11 MODULES THREADS LIBSYSTEMD JSON LCMS2
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-05-11 8:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-10 23:48 JSON Parsing Edge Case T.V Raman
2018-05-10 23:56 ` Noam Postavsky
2018-05-11 2:30 ` T.V Raman
2018-05-11 8:45 ` Basil L. Contovounesios
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).