Skip to content

check-json doesn't detect duplicate keys #554

Closed
@adamchainz

Description

The YAML check does this since #351 but since the json module's default behaviour is to ignore duplicates, duplicates are still possible in JSON. I think a small object_pairs_hook can be used to detect duplicates?

Activity

MiHarsh

MiHarsh commented on Feb 7, 2021

@MiHarsh

Hello Sir, I didn't understand exactly what we have to do. Do we need to add something to check for duplicates? If duplicate values found then we need to raise error? or something else? Please help !!

Do we need to return retval = 1 if found duplicates,so as to denote error in the file?

AdityaKhursale

AdityaKhursale commented on Feb 16, 2021

@AdityaKhursale
Contributor

Hi @asottile

I opened PR #558 for this issue. Did local verification for +ve/-ve test scenarios.

However, CI is failing. Could you please help review and let me know what need to be changed?

This is my first contribution in this repo. I am not very familiar with CI checks here and also, fairly new to open source.
Would appreciate your help.

Following is the local verification -

image

asottile

asottile commented on Feb 16, 2021

@asottile
Member

I commented on the PR 👍

adamchainz

adamchainz commented on Feb 18, 2021

@adamchainz
Author
marcindulak

marcindulak commented on Aug 28, 2021

@marcindulak

Can this check be made optional, so there is an option to restore the original check-json behavior where duplicate keys are allowed? @asottile

asottile

asottile commented on Aug 28, 2021

@asottile
Member

I don't think so, no -- duplicate keys are a mistake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Participants

    @adamchainz@asottile@marcindulak@AdityaKhursale@MiHarsh

    Issue actions

      check-json doesn't detect duplicate keys · Issue #554 · pre-commit/pre-commit-hooks