4

I face a problem when trying to convert a valid json-file into powershell-internal representation with the following code snippet:

[string]$changes = Get-Content -Path "C:\some\directory\with\file.json"
[PSCustomObject]$changes = ConvertFrom-Json -InputObject $Changes

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

The Powershell version in use is v5.1 which does not even support a Name flag, so I am a bit confused and can't seem to find a solution.

Any help appreciated...

Daniel
  • 578
  • 6
  • 18
  • I am running powershell 5.1.17134.228 and I dont have a problem with the example json I used to test. do you mind to share the json you try to deserialize? – Bhaal22 Jun 04 '20 at 09:58
  • it contains sensible information, therefore I cannot share it :/ but it is definitely valid and conforms to all conventions. – Daniel Jun 04 '20 at 09:59
  • no problem. was reading this link: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/convertfrom-json?view=powershell-7 check if you have comments in your json. – Bhaal22 Jun 04 '20 at 10:01
  • the json-files are automatically generated, there are no comments inside (I checked again). json-format is not supportive of commenting anyways, I thought. I thought about whether there are certain key-names that must not be used? – Daniel Jun 04 '20 at 10:06
  • look at this: https://github.com/PowerShell/PowerShell/issues/1755 – Bhaal22 Jun 04 '20 at 10:09
  • I reproduced updating my test json with an empty "key" – Bhaal22 Jun 04 '20 at 10:10
  • Yeah, I found an empty key in my document. thanks, I will provide this question with a correct answer once I sorted out my errors, unless you want to answer. – Daniel Jun 04 '20 at 10:13
  • will answer yeah. glad to help ! – Bhaal22 Jun 04 '20 at 10:18

1 Answers1

8

Regarding this thread, input json contains empty key(s) which look to be not supported by this powershell cmdlet.

Bhaal22
  • 715
  • 4
  • 10