Storing a part of a json query result in a variable in powershell
json, powershell, powershell-3.0
Solution
Using PS V3:
$json = @'
{
"data": {
"langid": 7,
"results": [
{
"first_aired": "2010-11-15",
"name": "Accused",
"tvdbid": 72663
},
{
"first_aired": "2010-01-17",
"name": "Enzai: Falsely Accused",
"tvdbid": 135881
}
]
},
"message": "",
"result": "success"
}
'@
$psobj = ConvertFrom-Json $json
$psobj.data.results.tvdbid
72663
135881
Problem
I have the following output from a json query and I am looking for a way to search though it and pull the value for the tvdbid(the number 72663) and store it in a variable. In the example below you can see there are actually 2 results so I would like it to store the both in array. I am running powershell 3 on my pc so any v3 specific stuff should be ok. Out put ``` { "data": { "langid": 7, "results": [ { "first_aired": "2010-11-15", "name": "Accused", "tvdbid": 72663 }, { "first_aired": "2010-01-17", "name": "Enzai: Falsely Accused", "tvdbid": 135881 } ] }, "message": "", "result": "success" } ```