0

Need name in array if change flag is true eg list = [kernel,activemq] How to extract through PowerShell

[
    {
        "name"           : "kernel",
        "change_flag"    : "TRUE",
        "localpath"      : "setupfiles\\controlroom\\kernel.jar",
        "unpack"         : "FALSE",
        "filename"       : ["",""]
    },
    {
        "name"           : "activemq",
        "change_flag"    : "TRUE",
        "localpath"      : "setupfiles\\controlroom\\activemq.jar",
        "unpack"         : "FALSE",
        "filename"       : ["",""]
    },
    {
        "name"           : "ignite-server",
        "change_flag"    : "FALSE",
        "localpath"      : "setupfiles\\controlroom\\ignite-server.jar",
        "unpack"         : "FALSE",
        "filename"       : []
    }
]

1 Answer 1

1

Use the ConvertFrom-Json cmdet to convert your text to json, then you can filter using the Where-Object cmdlet:

$json = 
@'
[
    {
        "name"           : "kernel",
        "change_flag"    : "TRUE",
        "localpath"      : "setupfiles\\controlroom\\kernel.jar",
        "unpack"         : "FALSE",
        "filename"       : ["",""]
    },
    {
        "name"           : "activemq",
        "change_flag"    : "TRUE",
        "localpath"      : "setupfiles\\controlroom\\activemq.jar",
        "unpack"         : "FALSE",
        "filename"       : ["",""]
    },
    {
        "name"           : "ignite-server",
        "change_flag"    : "FALSE",
        "localpath"      : "setupfiles\\controlroom\\ignite-server.jar",
        "unpack"         : "FALSE",
        "filename"       : []
    }
]
'@

($json | ConvertFrom-Json) | Where-Object change_flag -eq 'TRUE' | Select-Object -ExpandProperty name
Sign up to request clarification or add additional context in comments.

2 Comments

i need only if change_flag = true than create list and add value of each name
I adopt my answer. Please give it a try

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.