Search notes:

PowerShell cmdLet ConvertFrom-Json

convertFrom-json converts a JSON document (a System.String object) to a PowerShell object.
$json = @'
{
  "ary": [
     "one",
     {
        "x": "eggs",
        "y": "why"
     },
     3
  ],
  "txt": "Hello world",
  "num": 42
}
'@

$obj = convertFrom-json $json
$obj.GetType().FullName
#
#  System.Management.Automation.PSCustomObject

#
#    $obj.ary is an array with three elements:
#

$obj.ary.GetType().FullName
#
# System.Object[]

$obj.ary.length
#
# 3

#
#    $obj.arry's first element
#

$obj.ary[0].GetType().FullName
#
# System.String

$obj.ary[0]
#
# one


#
#    $obj.arry's second element
#

$obj.ary[1].GetType().FullName
#
# System.Management.Automation.PSCustomObject

$obj.ary[1]
#
# x    y
# -    -
# eggs why

$obj.ary[1].x
#
# eggs

#
#   etc. etc. etc.
#


$obj.txt
#
#  Hello World

$obj.num
#
#  42
Github repository about-PowerShell, path: /cmdlets/json/convertFrom/basic.ps1

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
As the -asHashTable option indicates, the type of the returned object is System.Management.Automation.OrderedHashtable.
PS C:\>(convertFrom-Json $json -asHashtable).getType()
System.Management.Automation.OrderedHashtable
See also the PowerShell issue 1755.

See also

convertTo-json conversts a PowerShell object to a JSON document.
Powershell command noun: json
Object creation in PowerShell

Index