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

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


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

@'   {    "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"   }'@ | set-content jsonfile.json$json = (Get-Content "jsonfile.json" -Raw) | ConvertFrom-Json$json.psobject.properties.nameCARD_MODEL_TITLECARD_MODEL_SUBTITLECARD_MODEL_SELECTCARD_LANG_TITLECARD_LANG_DEVICE_LANGCARD_YEAR_TITLECARD_YEAR_LATESTSTEPS_MODELSTEPS_LANGUAGESTEPS_YEARBUTTON_BACKBUTTON_NEXTBUTTON_CLOSE

You can also eliminate the -join by using the -Raw switch with Get-Content