Edu Lorenzo
Edu Lorenzo

Reputation: 165

Extract specific string from array with PowerShell

String example

[{"identifier" : "value1"},{"identifier" : "value2"}]

Desired output

value1,value2

I will be using powershell for this, have gone though the string and its methods but can't put my finger on how. Any and all help will be appreciated.

Upvotes: 0

Views: 73

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 59031

I think you should have provided more information in order to get a better answer. To solve your problem, you could deserialize the JSON(or load the file first) using the ConvertFrom-Json cmdlet, select the identifier property and finally -join the result:

('[{"identifier" : "value1"},{"identifier" : "value2"}]' | ConvertFrom-Json).identifier -join ','

Then you get your desired output:

value1,value2

Upvotes: 3

Related Questions