i trying powershell , trying convert simple json file table format.
the json-file looks this:
{ "members" : [ { "id" : 1, "details" : [ { "firstname" : "adam" }, { "lastname" : "ant" } ] }, { "id" : 2, "details" : [ { "firstname" : "ben" }, { "lastname" : "boggs" } ] }, { "id" : 3, "details" : [ { "firstname" : "carl"} , { "lastname" : "cox" } ] } ] } powershell expression:
$jstring.members.details | select-object -property id, firstname, lastname output far (best got).. id missing
id firstname lastname -- --------- -------- adam ant ben boggs carl cox how accomplish that?
any appreciated
json not strength if @ data structure id not on same level first , last name nested in details. put data in here-string testing.
$json = @" { "members" : [ { "id" : 1, "details" : [ { "firstname" : "adam" }, { "lastname" : "ant" } ] }, { "id" : 2, "details" : [ { "firstname" : "ben" }, { "lastname" : "boggs" } ] }, { "id" : 3, "details" : [ { "firstname" : "carl"} , { "lastname" : "cox" } ] } ] } "@ | convertfrom-json | select-object -expand members $json | select id,@{name="firstname";e={$_.details | select -expand firstname}},@{name="lastname";e={$_.details | select -expand lastname}} i use calculated properties "nested" details associated each id
which gets me following results.
id firstname lastname -- --------- -------- 1 adam ant 2 ben boggs 3 carl cox
Comments
Post a Comment