GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ConvertFrom-Json silently throws away duplicated keys with identical casing · Issue #5199 · PowerShell/PowerShell

ConvertFrom-Json silently throws away duplicated keys with identical casing #5199

New issue
Copy link
New issue
Copy link
Closed
Closed
ConvertFrom-Json silently throws away duplicated keys with identical casing#5199
Copy link
Labels
Breaking-Changebreaking change that may affect usersbreaking change that may affect usersResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issues

Description

@bergmeister
Christoph Bergmeister (bergmeister)
opened on Oct 22, 2017
Issue body actions

If the JSON contains duplicate keys with the same casing, then only the last key is used and the others are silently thrown away. The code in JsonObject.cs here actually caters for this case and would throw an error but it never gets to that stage because JsonConvert.DeserializeObject here does not throw when there are duplicate keys and simply decides to take the last one.

Steps to reproduce

'{ "key":"value1", "key":"value2" }' | ConvertFrom-Json

Expected behavior

Either a warning that duplicated keys were disregarded or an error stating that duplicate keys are not allowed unless e.g something like. a -Force switch is used. Given that this would be a breaking change, it will probably have to be a warning.

Actual behavior

Only the last key is used when there are duplicate keys

key
---
value2

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0-beta.8
PSEdition                      Core
GitCommitId                    v6.0.0-beta.8-20-g0d5a6fbd71c31043d0eda82f7b0e2d4fb0431322
OS                             Microsoft Windows 10.0.15063
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. Christoph Bergmeister (bergmeister)
    changed the title [-]ConvertFrom-Json silently throws away duplicated keys[/-] [+]ConvertFrom-Json silently throws away duplicated keys with identical casing[/+] on Oct 22, 2017
  2. Steve Lee (SteveL-MSFT)
    added
    Area-Cmdlets-Utility
    Breaking-Changebreaking change that may affect usersbreaking change that may affect users
    on Oct 23, 2017
  3. iSazonov commented on Oct 23, 2017

    @iSazonov
    Ilya (iSazonov)
    on Oct 23, 2017
    Collaborator
    More actions

    It is really bug - Json don't allow duplicate keys with the same case.

  4. SteveL-MSFT commented on Oct 25, 2017

    @SteveL-MSFT
    Steve Lee (SteveL-MSFT)
    on Oct 25, 2017
    Member
    More actions

    As best as I can tell JSON doesn't require member names to be unique, only recommended.

  5. iSazonov commented on Oct 25, 2017

    @iSazonov
    Ilya (iSazonov)
    on Oct 25, 2017
    Collaborator
    More actions

    :-) I believe implementations "MUST" follow "SHOULD recommendations".

    In any case I think JsonConvert.DeserializeObject works incorrectly.

  6. bergmeister commented on Oct 25, 2017

    @bergmeister
    Christoph Bergmeister (bergmeister)
    on Oct 25, 2017
    ContributorAuthor
    More actions

    I found the first 2 answers here interesting and their statement is basically that although it is valid JSON from a puristic point of view, JSON parsing libraries have and can choose different behaviours without conflicting with the standard. Normally one should trust the foundation, which is Newtonsoft.Json, but I am with Ilya (@iSazonov) that it's behaviour is sub-optimal. If there is a way of at least detecting the duplicates then at least a warning would be nice. A detection should be possible using a custom converter type when calling JsonConvert.DeserializeObject but it might result in a higher computational cost.

  7. iSazonov commented on Oct 25, 2017

    @iSazonov
    Ilya (iSazonov)
    on Oct 25, 2017
    Collaborator
    More actions

    If the standard say "SHOULD" it allows for a reasonable deviation from the standard. This means that the API must have the option to turn on or off duplicate keys.

  8. bergmeister commented on Oct 25, 2017

    @bergmeister
    Christoph Bergmeister (bergmeister)
    on Oct 25, 2017
    ContributorAuthor
    More actions

    According to the author of Newtonsoft.Json in his comment here it does not seem to be possible, therefore a different library might need to be used unfortunately.

  9. SteveL-MSFT commented on Oct 26, 2017

    @SteveL-MSFT
    Steve Lee (SteveL-MSFT)
    on Oct 26, 2017
    Member
    More actions

    Is there a known use case that depends on duplicate keys? Otherwise, based on the standard's recommendation, I don't think we must support it and warning the user is sufficient.

  10. iSazonov commented on Oct 26, 2017

    @iSazonov
    Ilya (iSazonov)
    on Oct 26, 2017
    Collaborator
    More actions

    Neton.Json is very popular library - if they don't fix (won't fix) we can ignore this in code and only add notes in docs.

  11. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    microsoft-github-policy-serviceBot
    on Nov 16, 2023 – with Microsoft GitHub Policy Service
    Contributor
    More actions

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  12. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    microsoft-github-policy-serviceBot
    on Nov 16, 2023 – with Microsoft GitHub Policy Service
    Contributor
    More actions

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  13. microsoft-github-policy-service
    added
    Resolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or more
    on Nov 16, 2023
  14. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    microsoft-github-policy-serviceBot
    on Nov 16, 2023 – with Microsoft GitHub Policy Service
    Contributor
    More actions

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  15. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    microsoft-github-policy-serviceBot
    on Nov 23, 2023 – with Microsoft GitHub Policy Service
    Contributor
    More actions

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

  16. microsoft-github-policy-service
    closed this as completedon Nov 23, 2023
  17. Ryan Yates (kilasuit)
    added
    WG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issues
    and removed
    WG-Cmdlets-Utility
    on Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Breaking-Changebreaking change that may affect usersbreaking change that may affect usersResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.