How do you get the name field of a JSON object in Powershell if you don't know it? -


i have json file:

{     "card_model_title": "owner's manual",     "card_model_subtitle": "configure download",     "card_model_select": "select model",     "card_lang_title": "select language",     "card_lang_device_lang": "your device",     "card_year_title": "select model year",     "card_year_latest": "(latest)",     "steps_model": "model",     "steps_language": "language",     "steps_year": "model year",     "button_back": "back",     "button_next": "next",     "button_close": "close" } 

and syntax use convert json object in powershell one:

$json = (get-content "jsonfile.json") -join "`n" | convertfrom-json 

the thing want edit value of each pair name/value, name field may vary in other files, , since want single script every file has generic.

how name field of pair name/value without knowing name field beforehand? or in other words, want kind of: foreach ($i in $json)

thanks

you can use $json.psobject.properties.name after it's converted:

@'    {     "card_model_title": "owner's manual",     "card_model_subtitle": "configure download",     "card_model_select": "select model",     "card_lang_title": "select language",     "card_lang_device_lang": "your device",     "card_year_title": "select model year",     "card_year_latest": "(latest)",     "steps_model": "model",     "steps_language": "language",     "steps_year": "model year",     "button_back": "back",     "button_next": "next",     "button_close": "close"    } '@ | set-content jsonfile.json  $json = (get-content "jsonfile.json" -raw) | convertfrom-json  $json.psobject.properties.name  card_model_title card_model_subtitle card_model_select card_lang_title card_lang_device_lang card_year_title card_year_latest steps_model steps_language steps_year button_back button_next button_close 

you can eliminate -join using -raw switch get-content


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -