Iterating through a JSON file PowerShell

前端 未结 3 1096
孤街浪徒
孤街浪徒 2020-11-27 05:30

I am trying to loop through the below JSON file in PowerShell.

Without specifically naming the top tags (e.g. 17443 and 17444), as I do not know them in advance I ca

3条回答
  •  误落风尘
    2020-11-27 06:36

    Here's a simple regex-based solution. Assuming that $sRawJson contains your JSON input:

    $oRegex = [Regex]'(?:(?<="[345]":\{"value"\:\["))[^"]+'
    $cParts = $oRegex.Matches(($sRawJson -replace '\s')) | Select-Object -ExpandProperty "Value"
    

    Joining parts to get full names:

    for ($i = 0; $i -lt $cParts.Count / 3; $i++) { $cParts[($i * 3)..($i * 3 + 2)] -join ' ' }
    

提交回复
热议问题