I'm trying to convert JSON into hashtable in 5.1 version of Powershell. But the output is coming as an object again for FieldMapping Key. Can we get the key value pairs for FieldMapping key?
We have ConvertFrom-Json -AsHashtable in 7.1 version . Ideally trying to get the same o/p in 5.1 as well. What can I try next?
My json:
$json = '[
{
"EntityType": "IP",
"FieldMapping": [
{
"ColumnName": "FileHashCustomEntity"
"Identifier": "Address"
}
]
}
]'
My code:
$entities = $json | ConvertFrom-Json
$ht2 = @{}
$hash = $entities.psobject.properties | Foreach { $ht2[$_.Name] = $_.Value }
echo $ht2
My output:
Key : EntityType
Value : IP
Name : EntityType
Key : FieldMapping
Value : {@{ColumnName=FileHashCustomEntity; Identifier=Address}}
Name : FieldMapping
Expected output:
Key : EntityType
Value : IP
Name : EntityType
Key : FieldMapping
Value : {FileHashCustomEntity}
Name : FieldMapping