lbeaudoin
lbeaudoin

Reputation: 11

Convert Json Object to string with PowerShell

I'm trying to convert this :

tags: [
    { tagName : "O365" },
    { tagName : "Skype for Business" }
]

to "O365,Skype for Business" as a string.

Could anyone help me to accomplish this using Powershell ?

Upvotes: 1

Views: 20580

Answers (2)

Similarly,

$separator = ","
$tagname = (ConvertFrom-Json $json).tags.tagName
[String]::Join($separator,$tagname)

Or as a one-liner

[String]::Join(",",(ConvertFrom-Json $json).tags.tagName)

Upvotes: 1

PlageMan
PlageMan

Reputation: 802

Works only if you have only one "tags" property in your JSON :

$json = @"
{
    tags: [
        { tagName : "O365" },
        { tagName : "Skype for Business" }
    ]
}
"@

(ConvertFrom-Json $json | % tags | % tagName) -Join ", "

# result : O365, Skype for Business

Upvotes: 3

Related Questions