我正试图找到一种方法,将嵌套的JSON数据导出到CSV文件中的列中。
这是我们在第三方解决方案中的一个检查的JSON输出。
{
"url": "***",
"id": 46092,
"guid": "a200efc4-2b05-422a-8785-ca5868aa7c1d",
"name": "***",
"check_type": "FprXnet",
"check_type_name": "Real Browser, Chrome",
"check_type_api": "browser",
"enabled": true,
"location": "Finland, Helsinki",
"country_code": "FI",
"sla_percent_current_month": 99.44116132753345,
"timestamp_utc": "2023-07-31T13:45:03.563",
"severity": "I",
"value": 37106,
"unit": "ms",
"target_sla": null,
"check_symbol": "N7_M13522_C46092_FPR_20190619_141926_713",
"threshold_w": null,
"threshold_w_dynamic": null,
"threshold_e": null,
"threshold_e_dynamic": null,
"threshold_lo_w": null,
"threshold_lo_w_dynamic": null,
"threshold_lo_e": null,
"threshold_lo_e_dynamic": null,
"scheduled_inclusion": null,
"scheduled_exclusion": "mon-sun : 01:00-01:15;",
"interval_seconds": 600,
"last_result_details": {
"message": "10 steps, 10 pages, 296 urls, 185350/46334226 sent/received bytes",
"attempts": 1,
"result_code": 0
},
"tags": {
"24/7 procedure": [
"24/7"
],
"Country": [
"Finland"
],
"Environment": [
"Prod"
],
"ITSystemCode": [
"***"
]
}
},
CSV的导出方式如下:
我需要做的是添加其他列:
(“24/7程序”、“国家/地区”、“环境”和“ITSystemCode”)
在以下嵌套信息的CSV文件中。
"tags": {
"24/7 procedure": [
"24/7"
],
"Country": [
"Finland"
],
"Environment": [
"Prod"
],
"ITSystemCode": [
"***"
]
}
这是我目前得到的剧本:
$response = Invoke-RestMethod 'https://***.***.com/v3/checks?enabled=true&auth_ticket=***' -Method 'GET'
$date = Get-Date -Format "MM-dd-yyyy-HH-mm"
$response | Select-Object -Property name,location,id,tags,timestamp_utc | Export-Csv -Path "Checks_$date.csv" -NoTypeInformation -Delimiter ";"
我正在尝试导出CSV文件,以便它包含以下列:
名称、位置、id、标签(“24/7过程”、“国家/地区”、“环境”、“ITSystemCode”)、时间戳_ utc
我试着遵循这一点,但我无法让它发挥作用/我现在正从Python过渡到PowerShell,所以我并不真正理解这一点。