[Pharo-users] JSON keys not quoted?

Ben Coman btc at openinworld.com
Fri Feb 22 21:53:01 EST 2019


Just curiousity... Is an idempotent round trip required/expected ?

cheers -ben

On Sat, 23 Feb 2019 at 05:24, Sven Van Caekenberghe <sven at stfx.eu> wrote:

> Good catch.
>
> Indeed, JSON keys have to be strings.
>
> The question is, should the writer convert them for you, or should you
> simply not use them ?
>
> I mean, there are many Pharo constructs that cannot be converted to JSON.
>
> Some could be output to JSON, but you won't be able to read them back in.
>
> So, if conversion would happen, the dictionary with integer keys will be
> read back with strings keys.
>
> In STON, keys can be anything, even complex objects, like in Pharo itself.
>
> What will you do with { (1 at 2)->100 } asDictionary in JSON ?
>
> I have to think about this.
>
> > On 22 Feb 2019, at 21:21, Esteban Maringolo <emaringolo at gmail.com>
> wrote:
> >
> > If you convert a Dictionary with numbers as keys it will produce not
> > valid JSON [1], since all object keys must be quoted.
> >
> > E.g.
> > NeoJSONWriter toString: (Dictionary with: 1->'foo').
> > or
> > (Dictionary with: 1->'foo') asJson
> >
> > Should the library generate quoted keys?
> >
> > Seaside's WAJsonCanvas is manual, so it is up to the developer to
> > render the object properly, but NeoJSON does it automatically.
> >
> > In Javascript this will throw a syntax error:
> >> JSON.parse('{1: "foo"}')
> >
> > And this would generate a quoted key when serialized:
> >> JSON.stringify({1: "foo"})
> >> {"1": "foo"}
> >
> > So my question is: should the library quote whatever you put as key in
> > order to produce valid JSON syntax? [2]
> >
> > Regards.
> >
> > [1] https://jsonlint.com/
> > [2]
> https://www.ecma-international.org/publications/standards/Ecma-404.htm
> >
> > Esteban A. Maringolo
> >
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/attachments/20190223/a835f6f5/attachment.html>


More information about the Pharo-users mailing list