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

Behaviour of json validation wrt duplicate keys #2610

Closed
ewoutkramer opened this issue Oct 23, 2023 · 4 comments · Fixed by #2708
Closed

Behaviour of json validation wrt duplicate keys #2610

ewoutkramer opened this issue Oct 23, 2023 · 4 comments · Fixed by #2708
Assignees

Comments

@ewoutkramer
Copy link
Member

How to deal with json resources with duplicate keys?

{
    "a" : "x",
    "a" : "y"
}

The Json ECMA spec is silent about it, the RFC "recommends" unique keys, and the FHIR spec, luckily, is explicit: these are not allowed.

The fact that the JSON spec itself is not explicit is probably the reason that Json.net will not complain, the default behaviour is to let subsequent occurrences of a key overwrite the previous ones:

https://www.newtonsoft.com/json/help/html/P_Newtonsoft_Json_Linq_JsonLoadSettings_DuplicatePropertyNameHandling.htm

  • We should hardwire this setting to "Error" for Json.net
  • In the new parsers, we are using a forward-only json reader, so the task of detecting this rests on our own shoulders.
@ewoutkramer
Copy link
Member Author

Marking this as a bug, since we're not compliant to the FHIR spec.

@brianpos
Copy link
Collaborator

brianpos commented Oct 23, 2023

I think there is already a test for this in the new parser, but I'm not 100%.
(or maybe I have something local still...)
Update: Nope, that's not one of the cases I was working on.

@wardweistra
Copy link
Member

Please also add trailing commas to this! See https://chat.fhir.org/#narrow/stream/179239-tooling/topic/Simplifier.20Packages/near/398385874

{
  "resourceType": "Patient",
  "id": "PatDisp8C66632E5A2E111BE05400144FF84F18",
  "identifier": [
    {
      "system": "https://fhir.infoway-inforoute.ca/NamingSystem/ca-on-patient-hcn",
      "value": "5259156783",
      }
  ],
  "name": [
    {
      "family": "Chen",
      "given": [
        "Patrick",
      ]
    }
  ],
  "gender": "male",
  "birthDate": "1961-01-01",
}

CleanShot 2023-10-25 at 12 03 52@2x

@ewoutkramer ewoutkramer self-assigned this Jan 24, 2024
@mmsmits mmsmits assigned Kasdejong and unassigned ewoutkramer Feb 13, 2024
@Kasdejong Kasdejong linked a pull request Feb 13, 2024 that will close this issue
ewoutkramer added a commit that referenced this issue Feb 15, 2024
…e-properties-while-parsing

#2610 signal duplicate properties while parsing
@wardweistra
Copy link
Member

Yay!

So I guess trailing commas should get it's own issue, right?

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