help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can the json reader be a bit more lenient?


From: Yuri Khan
Subject: Re: Can the json reader be a bit more lenient?
Date: Sun, 4 Aug 2019 01:47:42 +0700

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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]