I'm working with some JSON data in PowerShell. Some elements are multi-valued, delimited with a semi-colon, but its not always the same elements that are multi-valued. I would like to convert multi-valued elements, where ever they may occur, into JSON arrays.
I'm having trouble doing this. I've worked out a way to identify which elements are multi-valued, but am unsure how to split them when outputting the entire JSON. Do I need to construct a custom PSObject and breakout multi-valued elements into an array before exporting as JSON? That seems like a lot of overhead for a simple task.
Starting example
{
"Title": "Civil War Diary - Original and Transcript",
"Date Created": "1863",
"Access Rights": "Open Access",
"Identifier": "e9f44e22b9a285c1c3e2ac0307d113f3",
"Resource Type": "Text; Still Image"
}
Desired output
{
"Title": "Civil War Diary - Original and Transcript",
"Date Created": "1863",
"Access Rights": "Open Access",
"Identifier": "e9f44e22b9a285c1c3e2ac0307d113f3",
"Resource Type": [
"Text",
"Still Image"
]
}
"Resource Type"
?for res_type in data["Resource Type"]
and it's suddenly a flat string, I end up iterating over each individual letter...) If a field can be a list, it should just always be a list.