Error message: Cannot process argument because the value of argument "name" is not valid. Change the value of the "name" argument and run the operation again.
If a JSON object contains a key whose value is the empty string, convertFrom-json
will throw Cannot process argument because the value of argument "name" is not valid. Change the value of the "name" argument and run the operation again., as demonstrated with the following snippet:
$json = @'
{
"": "emptyKey"
}
'@
convertFrom-json $json
PowerShell 7 added the option
-asHashTable
which will happily create an object with an empty key:
PS C:\> convertFrom-json -asHashTable $json
Name Value
---- -----
emptyKey
PS C:\>(convertFrom-Json $json -asHashtable).getType()
System.Management.Automation.OrderedHashtable