I have this JSON file:
{
"CARD_MODEL_TITLE": "OWNER'S MANUAL",
"CARD_MODEL_SUBTITLE": "Configure your 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 the syntax I use to convert it to a JSON object in Powershell is this one:
$json = (Get-Content "jsonfile.json") -join "`n" | ConvertFrom-Json
The thing is that I want to edit the value of each pair name/value, but the name field may vary in other files, and since I want a single script for every file this has to be generic.
How do I get the name field of a pair name/value without knowing the name field beforehand? Or in other words, I want a kind of: foreach ($i in $json)
Thanks
You can use $json.psobject.properties.name after it's converted:
You can also eliminate the
-join
by using the-Raw
switch withGet-Content