Skip to main content

Restructure JSON body into hashtable

 

$bodyjson = @"
{
    "logtype": "testlogs2",
    "logbody": {
        "computername":"Device-123456",
        "user":"luca",
        "ouput":"registry key was set",
        "status":"success",
        "time":"xyz"
    }
}
"@

$bodyobject = ConvertFrom-Json $bodyjson
$logtype = $bodyobject.logtype
$logbodyobject = $bodyobject.logbody

$logbodyobjectmember = Get-Member -InputObject $logbodyobject | where {$_.Membertype -eq "NoteProperty"}

$outputproperties = @{}

foreach ($item in $logbodyobjectmember.name){
    $outputproperties.add($item, $logbodyobject.$item)
}