ConvertFrom-Json fails to parse project.lock.json

See original GitHub issue
$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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:17 (17 by maintainers)

github_iconTop GitHub Comments

3reactions
kitthollandcommented, Nov 26, 2016

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.

2reactions
kitthollandcommented, Jun 7, 2018

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - npm "failed to parse json"
Mostly, this error is due to a syntax error in package.json file. In my case, the opening curly brace for dependencies object in ......
Read more >
ConvertFrom-Json - PowerShell
The ConvertFrom-Json cmdlet converts a JavaScript Object Notation (JSON) formatted string to a custom PSObject or Hashtable object that has a property for ......
Read more >
ConvertFrom-Json fails to parse project.lock.json
ConvertFrom -Json fails to parse project.lock.json ... Expected: PowerShell should be able to parser the json data. Actual: A useless error message ...
Read more >
Why is Convertfrom-Json giving me an error with this file?.md
I get an error: ConvertFrom-Json: Conversion from JSON failed with error: Unexpected character encountered while parsing value: C. Path '', line ...
Read more >
Read/Write JSON Files with Node.js
Learn to use fs module to interact with the filesystem; Persist data to a JSON file; Use JSON.parse and JSON.stringify to convert data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found