Convert JSON array object to String in Powershell Convert JSON array object to String in Powershell json json

Convert JSON array object to String in Powershell


ConvertFrom-Json may work for you. Here's an example of converting your JSON string to an array of PowerShell objects, then joining the tags for each object with a comma delimiter:

$json = @"[    {        "Ack":  "no",        "Rule":  "dont",        "Tags":  [                     "server"                 ],        "Type":  "blue"    },    {        "Ack":  "no1",        "Rule":  "knock",        "Tags":  [                     "yellow",                     "green"                 ],        "Type":  "multiplecolour"    }]"@(ConvertFrom-Json -InputObject $json) `    | ForEach-Object { $_.Tags = ($_.Tags -join ","); $_ } `    | ConvertTo-Json `    | Out-File -FilePath new.json

EDIT: Note (as @mklement0 points out), the parentheses around ConvertFrom-Json are required to force the enumeration of the results as an array of objects through the pipeline.