* Can the json reader be a bit more lenient?
@ 2019-07-31 11:52 ndame
2019-08-03 16:14 ` Alex Kost
2019-08-03 18:47 ` Yuri Khan
0 siblings, 2 replies; 3+ messages in thread
From: ndame @ 2019-07-31 11:52 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org
Lately I've been using emacs for some text data processing, and the
input is json sometimes. The problem is the json often comes like
this:
[{'time1: '8:00', 'time2': '13:00', ...
and the emacs reader chokes on it saying
doesn't start with "!
Now I know the json standard says attribute names should be double quoted,
but can it be somehow persuaded to accept single quotes instead?
It would be great to have an option for this when I know the data is
correct, only it uses single quotes instead of doubles.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Can the json reader be a bit more lenient?
2019-07-31 11:52 Can the json reader be a bit more lenient? ndame
@ 2019-08-03 16:14 ` Alex Kost
2019-08-03 18:47 ` Yuri Khan
1 sibling, 0 replies; 3+ messages in thread
From: Alex Kost @ 2019-08-03 16:14 UTC (permalink / raw)
To: ndame; +Cc: help-gnu-emacs@gnu.org
ndame (2019-07-31 13:52 +0200) wrote:
> Lately I've been using emacs for some text data processing, and the
> input is json sometimes. The problem is the json often comes like
> this:
>
> [{'time1: '8:00', 'time2': '13:00', ...
>
> and the emacs reader chokes on it saying
>
> doesn't start with "!
This error comes from 'json-read-string' function.
> Now I know the json standard says attribute names should be double quoted,
> but can it be somehow persuaded to accept single quotes instead?
Not easily: I think the only way is to override the mentioned function.
> It would be great to have an option for this when I know the data is
> correct, only it uses single quotes instead of doubles.
I think this feature request should be sent with "M-x report-emacs-bug".
It's unlikely it will be noticed on this mailing list.
--
Alex
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Can the json reader be a bit more lenient?
2019-07-31 11:52 Can the json reader be a bit more lenient? ndame
2019-08-03 16:14 ` Alex Kost
@ 2019-08-03 18:47 ` Yuri Khan
1 sibling, 0 replies; 3+ messages in thread
From: Yuri Khan @ 2019-08-03 18:47 UTC (permalink / raw)
To: ndame; +Cc: help-gnu-emacs@gnu.org
On Wed, Jul 31, 2019 at 6:52 PM ndame <emacsuser@freemail.hu> wrote:
>
> Lately I've been using emacs for some text data processing, and the
> input is json sometimes. The problem is the json often comes like
> this:
>
> [{'time1: '8:00', 'time2': '13:00', ...
That’s a bug in the program generating such input.
> and the emacs reader chokes on it saying
>
> doesn't start with "!
As it well should.
> Now I know the json standard says attribute names should be double quoted,
> but can it be somehow persuaded to accept single quotes instead?
The ECMA-404 specification explicitly discourages this:
A conforming processor of JSON texts should not accept any inputs
that are not conforming JSON text.
> It would be great to have an option for this when I know the data is
> correct, only it uses single quotes instead of doubles.
IMO it’s a bad idea. If a program says it produces JSON, it should
produce well-formed JSON, with the correct quotes. We already have a
precedent of parsers forgiving small spec violations; HTML. It grew to
become a monster.
If you want to parse documents that are almost JSON but use the wrong
quote character, use a YAML parser. YAML is a superset of JSON with a
lot of syntax sugar.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-08-03 18:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-31 11:52 Can the json reader be a bit more lenient? ndame
2019-08-03 16:14 ` Alex Kost
2019-08-03 18:47 ` Yuri Khan
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).