Skip to content

ConvertFrom-Json fails to parse project.lock.json #1755

Closed

Description

$json = gc project.lock.json -Raw
ConvertFrom-Json $json

Expected: PowerShell should be able to parser the json data.
Actual: A useless error message which does not tell me what went wrong

ConvertFrom-Json : Cannot process argument because the value of argument "name" is not valid. Change the value of the
"name" argument and run the operation again.
At line:1 char:1
- ConvertFrom-Json $json
- ~~~~~~~~~~~~~~~~~~~~~~
  - CategoryInfo          : InvalidArgument: (:) [ConvertFrom-Json], PSArgumentException
  - FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.ConvertFromJsonCommand

Activity

  1. added this to the milestone on Aug 12, 2016
  2. added
    Issue-BugIssue has been identified as a bug in the product
    Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributors
    on Oct 11, 2016
  3. kittholland commented on Nov 26, 2016

    @kittholland
    Contributor

    Bug is due to empty name for json dictionary entry, which appears to be valid by json standards, issue I believe is when converting to psobject:

    Example from the project.lock.json:

    "projectFileDependencyGroups": {
    "": [
    "System.Management.Automation >= 6.0.0-*"
    ],

    thrown from line 4474 in MshMemberInfo.cs

                    if (String.IsNullOrEmpty(name))
                    {
                        throw PSTraceSource.NewArgumentException("name");
                    }
    

    "Cannot process argument because the value of argument "name" is not valid. Change the value of the "name" argument and run the operation again."

    Reproducible with the following simple json:

    {
    "": "Test"
    }

    I am uncertain how to proceed further to fix this issue, hopefully this helps.

  4. SteveL-MSFT commented on Nov 28, 2016

    @SteveL-MSFT
    MemberAuthor

    Kitt Holland (@kittholland) thanks for looking into this, best as I can tell per http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf, an empty string as the name is allowed and works in javascript. I guess the next step is to determine if the issue is in newtonsoft json parser.

  5. kittholland commented on Nov 28, 2016

    @kittholland
    Contributor

    From what I could see in the debugger, newtonsoft was OK with it, but converting the Jobject into a PSObject failed because the name was empty.

  6. SteveL-MSFT commented on Nov 28, 2016

    @SteveL-MSFT
    MemberAuthor

    Ok, that makes sense (on why it failed). A HashTable will accept an empty string key, so it seems we should have PSObject support it as well. Kitt Holland (@kittholland) are you going to work on a fix?

  7. kittholland commented on Nov 28, 2016

    @kittholland
    Contributor

    I have not looked deeply into what would be required, but I can give it a try.

  8. joeyaiello commented on Dec 8, 2016

    @joeyaiello
    Contributor

    We should also handle the Invoke-WebRequest/Invoke-RestMethod scenario where you're able to post a null JSON key as a string or as an object.

  9. modified the milestones: , on Feb 28, 2017
  10. 18 remaining items

  11. modified the milestones: , on Oct 14, 2017
  12. modified the milestones: , on Oct 16, 2017
  13. SteveL-MSFT commented on Oct 16, 2017

    @SteveL-MSFT
    MemberAuthor

    Forgot about the discussion in #2820. Introducing a json specific type isn't happening in 6.0.0 timeframe.

  14. bergmeister commented on Nov 14, 2017

    @bergmeister
    Contributor

    Steve Lee (@SteveL-MSFT) Can this issue be closed since PR #5043 provides a workaround via the -AsHashTable switch?

  15. SteveL-MSFT commented on Nov 15, 2017

    @SteveL-MSFT
    MemberAuthor
  16. DarwinJS commented on Jun 7, 2018

    @DarwinJS
    Contributor

    Any work arounds to this without upgrading PowerShell?

  17. kittholland commented on Jun 7, 2018

    @kittholland
    Contributor

    Darwin (@DarwinJS) You can either modify your json to be compatible with PSObjects, or you will need to modify/create a cmdlet to convert from json into hashtables.

  18. bergmeister commented on Jun 7, 2018

    @bergmeister
    Contributor

    Darwin (@DarwinJS) Since PowerShell Core is side by side and you can even get a self-contained version, you could just call into a newer version of pwsh from an old version of pwsh.

  19. DarwinJS commented on Jun 7, 2018

    @DarwinJS
    Contributor

    This is part of tooling that runs on thousands of machines I don't control and actually needs to be a single script with no public repo dependencies - so I resorted to the -replace method. Thanks.

  20. added a commit that references this issue on Dec 5, 2024
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

    Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions