Minor Powershell question.
I'm wanting to recursively run through a directory and all subdirectories, read JSON files from them, and merge them all into one massive CSV.
Here's my attempt:
While I can iterate fine and if I output to the console it displays properly, the problem is in writing the CSV. CSV comes out like this:
Input, Output, Groups are all properties in the JSON and... have properties of their own with values.
I think the problem is due to each property having 1 or more items which also have values which is where I'm stumped. I'm not entirely sure what the best way to "output" these objects into what is basically a flat array. Input, Output, and Groups are consistent throughout all the JSON files. Input will always have "item" child properties in 1 or more quantities and each of them will have a "count" value. Output will be similar to input. Groups is the easiest as it has 1 or more items under it but no sub-items, ever.
JSON example:
Thoughts? I'm a bit puzzled.
Hope this all makes sense. 
I'm wanting to recursively run through a directory and all subdirectories, read JSON files from them, and merge them all into one massive CSV.
Here's my attempt:
Code:
$output = ".\combined.csv"
Get-ChildItem .\*.recipe -Recurse| Foreach-Object {
$item = (Get-Content $_ -Raw) | ConvertFrom-Json
Add-Content -Path $output -Value $item
}
While I can iterate fine and if I output to the console it displays properly, the problem is in writing the CSV. CSV comes out like this:
Code:
@{input=System.Object[]; output=; groups=System.Object[]}
Input, Output, Groups are all properties in the JSON and... have properties of their own with values.
I think the problem is due to each property having 1 or more items which also have values which is where I'm stumped. I'm not entirely sure what the best way to "output" these objects into what is basically a flat array. Input, Output, and Groups are consistent throughout all the JSON files. Input will always have "item" child properties in 1 or more quantities and each of them will have a "count" value. Output will be similar to input. Groups is the easiest as it has 1 or more items under it but no sub-items, ever.
JSON example:
Code:
"input": [
{
"item": "item1",
"count": 25
},
{
"item": "item2",
"count": 3
}
],
"output": {
"item": "someItem",
"count": 1
},
"groups": [
"groupA",
"groupB",
"groupC"
]
Thoughts? I'm a bit puzzled.