1

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 ?

2
  • What have you tried so far? Commented Apr 16, 2018 at 13:04
  • get-help ConvertFrom-Json Commented Apr 16, 2018 at 13:13

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

In PowerShell 3+ I find it easier to just use ForEach-Object for such things: ConvertFrom-Json $json | % tags | % tagName
@Joey : You are right, Syntax is simpler with %, I updated the answer.
1

Similarly,

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

Or as a one-liner

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.