Skip to content
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

Duplicate keys aren't cool! #13

Open
thejh opened this issue Nov 12, 2011 · 27 comments
Open

Duplicate keys aren't cool! #13

thejh opened this issue Nov 12, 2011 · 27 comments

Comments

@thejh
Copy link

thejh commented Nov 12, 2011

$ echo '{"a":1,"a":2}' | jsonlint
The "sys" module is now called "util". It should have a similar interface.
{
  "a": 2
}
$ 
@zaach
Copy link
Owner

zaach commented Nov 13, 2011

By default we simply follow the spec, but it wouldn't hurt to have as an option.

@thejh
Copy link
Author

thejh commented Nov 13, 2011

I guess I expect something with "lint" in the name to do some plausibility checking.

@Klortho
Copy link

Klortho commented Jan 2, 2013

+1
Any chance this will get fixed?
Also, I'd think it should complain about empty-string keys:

{ "": "foo" }

@rngadam
Copy link

rngadam commented Sep 18, 2013

+1 just got bitten by a bug caused by a duplicate key, would love to use a tool such as jsonlint to catch these errors in my automated tests.

@dharasty
Copy link

JavaScript, JSON, and Python all allow a key to be duplicated. (It is NOT a syntax error; the value of the last occurrence of the key is kept.)

JavaScript, JSON, and Python all allow the empty string as a valid key. (It is NOT a syntax error.)

So my vote is that these are NOT flagged as error or even warnings, unless the JSONLint user specifically calls for them via a commandline option.

@rngadam
Copy link

rngadam commented Jan 28, 2014

@dharasty : what's the point of a lint tool if it doesn't catch anything more than the real parser? I think it's more than likely that there's an issue when there are duplicate keys...

@mattfenwick
Copy link

@rngadam checking for duplicate keys was a big problem for me, and since this issue is still unresolved after 2 years, I had to bite the bullet and implement my own checker.

I agree with your position -- most people expect keys to be unique, key/value pairs to not be silently discarded, and the resultant object to match the JSON input. All of these reasonable expectations are broken, making debugging quite painful. 👍

@dharasty
Copy link

I see your points (@rngadam and @mattfenwick) and understand that if this as "bitten" you, you'd like a checker.

I guess I just don't use linting tools that way: I tend to use them to validate syntax and to pretty-format.

I do scratch my head a bit at "most people expect ... the resultant object to match the JSON input". I'm not sure what that means if the JSON input in the presence of multiple identical keys, which is allowed by in the serialization defined in the JSON spec, but clearly not in the concept of a JSON (or JavaScript) object. Therefore I'm not sure what is "reasonable" to expect.

I -- for one -- expect that repeated keys silently trump prior instances of the same key... but just because it it my experience that that is true (in JSON, JavaScript, and Python).

Is this your view?: "because purposeful use duplicated keys are very rare, when seen, it JSONLint should emit a warning".

@Delagen
Copy link

Delagen commented Dec 19, 2014

+1

1 similar comment
@odino
Copy link

odino commented Apr 21, 2015

+1

@pixelastic
Copy link

I would also like to have jsonlint emit a warning on duplicate keys.

@itsikavidan
Copy link

+1

@amire80
Copy link

amire80 commented Jul 8, 2015

It actually happened to me at least once that a duplicate key written manually by mistake caused a real bug, so it would be nice to get a warning about that. In my case I'd prefer that to be a fatal error in the build that would force me to fix it before deployment.

@hotoo
Copy link

hotoo commented Aug 24, 2015

👍

@mikeabiezzi
Copy link

100% agree. There is no reason to purposefully hard code duplicate keys in a JSON file. A linter should definitely check for this. Via an option is reasonable, considering it's not part of the JSON spec. Any chance this will get added? Need help creating a PR?

@azamat-sharapov
Copy link

A pure JavaScript version of the service provided at jsonlint.com.

Judging from readme, this projects claims to work like jsonlint.com, but compared to jsonlint.com - it doesn't detect duplicates.

@adbl
Copy link

adbl commented Nov 10, 2016

We use this library for linting manually written json files, and this problem caused confusion and time wasted more than once. I'd be happy to have it as an option if it shouldn't be the default behavior...

@hypery2k
Copy link

any chance to get this feature?

@Christian-Yang
Copy link

Finally, is there a check that supports duplicate keys?

@AndersDJohnson
Copy link

Would love this.

@WindRider7
Copy link

Would love to see this also.

@kkor
Copy link

kkor commented Jul 31, 2018

7 years later, still nothing?

@GGurbanov
Copy link

9 years later, humanity is on the verge of extinction (COVID-19) - still nothing...(

@FuDesign2008
Copy link

OMG, this issue is still open.

@jpalardy
Copy link

I stumbled on this thread, for this exact problem.

The jsonlint-mod fork seems to solve that problem and exposes the same bin.

Posting here in case it helps someone else.

@rdmarsh
Copy link

rdmarsh commented Feb 9, 2022

I know duplicate keys are valid, but I'd imagine most occurrences are a mistake and unexpected and unwanted.

@HolgerJeromin
Copy link

https://github.com/prantlf/jsonlint seems to be maintained

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

No branches or pull requests