[Pharo-users] JSON keys not quoted?

Esteban Maringolo emaringolo at gmail.com
Fri Feb 22 15:21:49 EST 2019

If you convert a Dictionary with numbers as keys it will produce not
valid JSON [1], since all object keys must be quoted.

NeoJSONWriter toString: (Dictionary with: 1->'foo').
(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]


[1] https://jsonlint.com/
[2] https://www.ecma-international.org/publications/standards/Ecma-404.htm

Esteban A. Maringolo

More information about the Pharo-users mailing list