Skylerdw
Skylerdw

Reputation: 357

PowerShell - JsonArray from file to Script

I have a file containing of:

[{
    'item1' : 'value1',
    'item2' : [
        'internalItem1' : 'value'
    ]
},
{
    'item1' : 'value2',
    'item2' : [
        'internalItem1' : 'value',
        'item2' : [
            'internalItem1' : 'value',
            'internalItem2' : 'value'
        ]
    ]
}]

I'd like to put it in an array of json objects. How can I do it? This is how I'm managing with a file containing of one JSON object:

$json = (Get-Content $fileLocation) | ConvertTo-Json

But the array of them is giving me nighthmares, how can I process this data?

Upvotes: 0

Views: 147

Answers (1)

MisterSeajay
MisterSeajay

Reputation: 4689

Looks like you need commas on the end of the lines:

[{
    'item1' : 'value1',
    'item2' : {
        'internalItem1' : 'value'
    }
},
{
    'item1' : 'value2',
    'item2' : {
        'internalItem1' : 'value',
        'item2' : [{
            'internalItem1' : 'value',
            'internalItem2' : 'value'
        }]
    }
}]

Upvotes: 1

Related Questions