試圖signing_certificate_id從下面的 json 片段中提取欄位,但不幸的是,資料沒有進入 excel 匯出。其他資訊正在進入 csv。(在某些情況下,這些代碼塊在同一個 json 中存在兩次以表示一個單獨的環境。
Json 片段:
{
"sfg_ping::production::standard_sp_connections": [
{
"name": "hhhh",
"entity_id": "https://hhhh.hhhh.com",
"contact_info": "[email protected]",
"sp_endpoint": "https://hhhh.hhhh.com/",
"sso_initialization_and_signature_policy": {
"sign_assertion_or_response": "assertion",
"sp_trust_model": "unanchored",
"signing_certificate_id": "gggggg",
"sp_initiated": {
"require_signed_authn_requests": false
}
},
正在使用的腳本:
Get-ChildItem "C:\Users\hhhh\appdev\targetfolder-json2" -Filter *.json -PipelineVariable file | ForEach-Object {
(Get-Content $_.pspath -Raw | ConvertFrom-Json).PSObject.Properties.Value | Select-Object @(
@{ l = 'filename'; e = { $file.Name }}, 'Name','contact_info', 'signing_certificate_id'
)
} | Export-Csv path\to\myexport.csv -NoTypeInformation
uj5u.com熱心網友回復:
您需要創建一個計算屬性來獲取嵌套的 JSON 屬性,類似于您所做的filename:
Get-ChildItem "C:\Users\hhhh\appdev\targetfolder-json2" -Filter *.json -PipelineVariable file | ForEach-Object {
(Get-Content $_.pspath -Raw | ConvertFrom-Json).PSObject.Properties.Value | Select-Object @(
@{ l = 'filename'; e = { $file.Name }}, 'Name','contact_info',
@{ l = 'signing_certificate_id'; e = { $_.sso_initialization_and_signature_policy.signing_certificate_id }}
)
} | Export-Csv path\to\myexport.csv -NoTypeInformation
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/528437.html
標籤:json电源外壳解析
