I am trying to convert json file to csv file using Powershell. The json file that I am trying to convert has multiple nested arrays. I want to expand them all. But I am able to expand only one sub-array at a time. Following is the file structure and the code I am working with:
This is a snapshot of my feed.json file:
{
"result": {
"problems": [
{
"id": "AHR157689",
"displayName": "YOCETJE",
"impact": "STRUCTURE",
"status": "OPEN",
"tagsOfEntities": [],
"ranked": [
{
"entityId": "843675746378564876",
"entityName": "HGFUTGYJDH",
"severityLevel": "8957685N8Y",
}
],
"affectedCounts": {
"INFRA": 1,
"STRUCTURE": 0,
"APPLICATION": 0,
},
"recoveredCounts": {
"INFRA": 0,
"STRUCTURE": 0,
"APPLICATION": 0,
},
"RootCause": true
}
}
}
}
And below is the code I am working with:
Get-Content C:Downloadsfeed.json -Raw | ConvertFrom-Json |
Select -Expand results | Select -Expand problem | ConvertTo-Csv |
Out-File C:Downloadsoutput.csv
With this above code I cam not getting the 'tagsofEntities' and 'ranked' data in the csv file. The column for tagsofEntities and ranked shows the value as "System.Object[]".
This is the output in output.csv fil. This all data comes in one cell.
AHR157689,"YOCETJE","STRUCTURE","OPEN","System.Object[]","System.Object[]","@{"INFRA": 1; "STRUCTURE": 0,"APPLICATION": 0}","@{"INFRA": 0;"STRUCTURE": 0;"APPLICATION": 0}","true"