Skip to content

Allow empty keys as defined in the JSON spec. #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

umulmrum
Copy link

Hi,

the lib currenty disallows empty JSON keys although they are allowed by the JSON spec. I found several other libs with similar issues, where fixes have been suggested and pulled, so I'm quite confident it is correct to allow empty keys.

My use case worked with this fix although I'm not sure if there are other implications (tests do not cover this).

@ibarabash
Copy link
Collaborator

Hi @umulmrum ,

Thanks for contributing and hope you found this lib useful for you.
I'm not sure object's key could be empty according to specification RFC8259 https://tools.ietf.org/html/rfc8259 , ECMA-404 http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf :

An object structure is represented as a pair of curly brackets
surrounding zero or more name/value pairs (or members). A name is a
string. A single colon comes after each name, separating the name
from the value.

To ensure we are talking on same side: are we talking about object's key as about name of name/value pair?
Could you please send part of JSON of your use-case and link to spec you found object's key could be empty? Maybe your specific JSON doesn't follow standard and tries to use object in case where array is suitable? :)

@ibarabash
Copy link
Collaborator

ibarabash commented Apr 18, 2018

Hm I found this one in ECMA-404:

The JSON syntax does not impose any restrictions on
the strings used as names, does not require that name strings be unique, and does not assign any
significance to the ordering of name/value pairs

So it allows following JSON:

{"": "value"}

Did you you mean this case @umulmrum ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants