You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ConvertFrom-Json fails to parse project.lock.json #1755
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
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?
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.
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.
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.
Activity
kittholland commentedon 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
"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.
SteveL-MSFT commentedon Nov 28, 2016
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.
kittholland commentedon Nov 28, 2016
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.
SteveL-MSFT commentedon Nov 28, 2016
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?
kittholland commentedon Nov 28, 2016
I have not looked deeply into what would be required, but I can give it a try.
Allow empty string names for PSObjects PowerShell#1755
joeyaiello commentedon Dec 8, 2016
We should also handle the
Invoke-WebRequest/Invoke-RestMethodscenario where you're able to post a null JSON key as a string or as an object.18 remaining items
SteveL-MSFT commentedon Oct 16, 2017
Forgot about the discussion in #2820. Introducing a json specific type isn't happening in 6.0.0 timeframe.
bergmeister commentedon Nov 14, 2017
Steve Lee (@SteveL-MSFT) Can this issue be closed since PR #5043 provides a workaround via the
-AsHashTableswitch?SteveL-MSFT commentedon Nov 15, 2017
Christoph Bergmeister (@bergmeister) agree!
DarwinJS commentedon Jun 7, 2018
Any work arounds to this without upgrading PowerShell?
kittholland commentedon Jun 7, 2018
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.
bergmeister commentedon Jun 7, 2018
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.
DarwinJS commentedon Jun 7, 2018
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.
Fix error in JSON parsing