平展以 "[" 开头的嵌套 .json 文件 |ConvertFrom-json 给出错误的输出



我正在尝试获得.json文件的格式,以便在使用| ConvertFrom-Json时提供正确的输出。我倾向于丢失很多信息,并且返回的对象不能作为所需函数的输入来压平.json文件。

我想从ConvertFrom-Json获得正确的输出,以便它与GitHub页面中的脚本Convert-JsonToCsv.ps1一起工作。

我有以下.json文件

[
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u0027670ed8e1-25f4-4c24-b9ea-04b861a4566fu0027)",
"enabled":  false
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u00273705e5ff-18e7-4051-9d6e-12cc93eca35bu0027)",
"presentationValues":  [
{
"@odata.type":  "#microsoft.graph.groupPolicyPresentationValueList",
"values":  [
{
"name":  "*",
"value":  null
}
],
"presentation@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u00273705e5ff-18e7-4051-9d6e-12cc93eca35bu0027)/presentations(u002715374e33-8b97-4d41-8253-9b90ce9bc645u0027)"
}
],
"enabled":  true
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u0027c12cd0b7-a46f-4cc5-8dbd-1ce17d69c702u0027)",
"enabled":  false
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u002763db8dde-bcaf-49de-8964-1f68371c4d2cu0027)",
"enabled":  false
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u0027b0689b0a-b725-4070-a5bf-32be09e495cfu0027)",
"enabled":  false
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u002784c82f32-04f7-4074-a5c4-3544a98208b8u0027)",
"enabled":  true
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u002708c228ef-25e3-45b2-9afe-47bb2f2ab7ebu0027)",
"presentationValues":  [
{
"@odata.type":  "#microsoft.graph.groupPolicyPresentationValueText",
"value":  "2",
"presentation@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u002708c228ef-25e3-45b2-9afe-47bb2f2ab7ebu0027)/presentations(u0027cb2eb670-db0b-4efc-97b3-36b7e13e576eu0027)"
}
],
"enabled":  true
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u00279777a6fc-7311-4842-a2ae-5b34e4c6b94au0027)",
"presentationValues":  [
{
"@odata.type":  "#microsoft.graph.groupPolicyPresentationValueList",
"values":  [
{
"name":  "[*.]didac.no",
"value":  null
},
{
"name":  "clikc.wcoomd.org",
"value":  null
},
{
"name":  "norsktollerforbund.sharepoint.com",
"value":  null
},
{
"name":  "https://p360pd.toll.no",
"value":  null
},
{
"name":  "https://regnskap-agrdra.dfo.no",
"value":  null
}
],
"presentation@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u00279777a6fc-7311-4842-a2ae-5b34e4c6b94au0027)/presentations(u0027cf6985ea-33cb-4bb8-bf10-02c1aa49f35fu0027)"
}
],
"enabled":  true
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u00273e3ef429-ba9c-4bf5-9c54-5caf3aac9831u0027)",
"presentationValues":  [
{
"@odata.type":  "#microsoft.graph.groupPolicyPresentationValueText",
"value":  "https://www.google.com",
"presentation@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u00273e3ef429-ba9c-4bf5-9c54-5caf3aac9831u0027)/presentations(u0027bb6876d7-90c5-4281-a9a2-7154ed9afd79u0027)"
}
],
"enabled":  true
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u002746436297-0d1e-45db-be13-5e3fccff84afu0027)",
"presentationValues":  [
{
"@odata.type":  "#microsoft.graph.groupPolicyPresentationValueText",
"value":  "2",
"presentation@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u002746436297-0d1e-45db-be13-5e3fccff84afu0027)/presentations(u0027d00346f1-de43-4797-bf2e-fbe1db8acbc6u0027)"
}
],
"enabled":  true
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u00277d66e7bd-0a01-4f66-8d76-690a58276985u0027)",
"enabled":  false
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u0027df68228c-1238-41da-975a-71ce2b241b12u0027)",
"presentationValues":  [
{
"@odata.type":  "#microsoft.graph.groupPolicyPresentationValueText",
"value":  "2",
"presentation@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u0027df68228c-1238-41da-975a-71ce2b241b12u0027)/presentations(u0027a0c5718b-5463-42a1-8888-18d2dea6622cu0027)"
}
],
"enabled":  true
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u0027bcbc275c-0c2e-41ee-826e-77a0c8ef3dfcu0027)",
"enabled":  true
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u0027732b39c3-e2c5-4c6c-a6a3-9b4fcdde3febu0027)",
"enabled":  true
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u002732cb2ceb-a08a-4406-8977-a1a124c2de42u0027)",
"presentationValues":  [
{
"@odata.type":  "#microsoft.graph.groupPolicyPresentationValueList",
"values":  [
{
"name":  "com.microsoft.browsercore",
"value":  null
}
],
"presentation@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u002732cb2ceb-a08a-4406-8977-a1a124c2de42u0027)/presentations(u0027f849b343-4761-4326-ae50-9dc1eeb87383u0027)"
}
],
"enabled":  true
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u00270a125ca8-f0eb-4914-83ee-a41ee85a0e2bu0027)",
"enabled":  true
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u0027c4282b30-71ac-4c45-b4e3-b317211fd5e8u0027)",
"presentationValues":  [
{
"@odata.type":  "#microsoft.graph.groupPolicyPresentationValueText",
"value":  "0",
"presentation@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u0027c4282b30-71ac-4c45-b4e3-b317211fd5e8u0027)/presentations(u00274f5c7fa8-a533-48e5-a0ba-bc4f5e9dbb16u0027)"
}
],
"enabled":  true
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u00271c484cb4-c95c-45ee-aae6-cfaafcae6d61u0027)",
"enabled":  false
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u0027124c9a03-7378-44b6-914b-e00f63dd399bu0027)",
"enabled":  true
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u002709d328bc-a4a6-414d-abe3-ed453ca82172u0027)",
"enabled":  true
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u0027fb18f15f-d16e-45f9-a79c-efa4da12203fu0027)",
"presentationValues":  [
{
"@odata.type":  "#microsoft.graph.groupPolicyPresentationValueText",
"value":  "2",
"presentation@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u0027fb18f15f-d16e-45f9-a79c-efa4da12203fu0027)/presentations(u0027e3bb6241-cdd2-4dec-a276-e6898a2725bdu0027)"
}
],
"enabled":  true
},
{
"definition@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u0027d4e64503-0338-4cae-9712-efec0461b8feu0027)",
"presentationValues":  [
{
"@odata.type":  "#microsoft.graph.groupPolicyPresentationValueText",
"value":  "4",
"presentation@odata.bind":  "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(u0027d4e64503-0338-4cae-9712-efec0461b8feu0027)/presentations(u0027c67624ce-2404-4740-a7d1-da572d847231u0027)"
}
],
"enabled":  true
}
]

我尝试过的是其他.json文件,但不是以"开头的文件;["并以"]"结尾;。以下内容:

$input = Get-Content -Path $jsonFileContents | ConvertFrom-Json

给出输出(命名为$input(:

definition@odata.bind                                                                                            enabled
---------------------                                                                                            -------
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('670ed8e1-25f4-4c24-b9ea-04b861a4566f')   False
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('3705e5ff-18e7-4051-9d6e-12cc93eca35b')    True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('c12cd0b7-a46f-4cc5-8dbd-1ce17d69c702')   False
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('63db8dde-bcaf-49de-8964-1f68371c4d2c')   False
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('b0689b0a-b725-4070-a5bf-32be09e495cf')   False
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('84c82f32-04f7-4074-a5c4-3544a98208b8')    True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('08c228ef-25e3-45b2-9afe-47bb2f2ab7eb')    True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('9777a6fc-7311-4842-a2ae-5b34e4c6b94a')    True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('3e3ef429-ba9c-4bf5-9c54-5caf3aac9831')    True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('46436297-0d1e-45db-be13-5e3fccff84af')    True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('7d66e7bd-0a01-4f66-8d76-690a58276985')   False
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('df68228c-1238-41da-975a-71ce2b241b12')    True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('bcbc275c-0c2e-41ee-826e-77a0c8ef3dfc')    True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('732b39c3-e2c5-4c6c-a6a3-9b4fcdde3feb')    True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('32cb2ceb-a08a-4406-8977-a1a124c2de42')    True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('0a125ca8-f0eb-4914-83ee-a41ee85a0e2b')    True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('c4282b30-71ac-4c45-b4e3-b317211fd5e8')    True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('1c484cb4-c95c-45ee-aae6-cfaafcae6d61')   False
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('124c9a03-7378-44b6-914b-e00f63dd399b')    True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('09d328bc-a4a6-414d-abe3-ed453ca82172')    True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('fb18f15f-d16e-45f9-a79c-efa4da12203f')    True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('d4e64503-0338-4cae-9712-efec0461b8fe')    True

因此丢失了很多信息。

使用其他类型的文件(以{..}开头和结尾(,我haev使用了以下内容,其中Flatten-PsCustomObject来自上方的git链接

$input = Get-Content -Path $inputFile | ConvertFrom-Json 
Flatten-PsCustomObject 'someString' $input 

这非常有效。我做错了什么/我该如何处理[…]-文件?感谢您对此事的意见!

这是一个常见的问题。通过管道将其发送到格式列表中,以查看不同的特性集。有时你必须指定";convertfrom-json-depth";大于2。问题不完全在于json数组。但默认输出(格式表(不会显示数组中对象之间不同数量的属性。

get-content file.json | convertfrom-json | format-list

相关内容

  • 没有找到相关文章

最新更新