Reputation: 11
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
Reputation: 513
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
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