ethan-s
3/8/2017 - 7:35 PM

Using PowerShell to Convert From JSON to CSV format

Using PowerShell to Convert From JSON to CSV format

function ConvertFrom-JsonToCsv {
    param(
        [Parameter(ValueFromPipeline)]
        $json        
    )

    Process {
        ($json | ConvertFrom-Json) | ConvertTo-Csv -NoTypeInformation
    }
}

# Is there a better way to do this with a foreach key in inputCSV do key:value?
'[{"Column 1": "1-1","Column 2": "1-2","Column 3": "1-3","Column 4": "1-4"},{"Column 1": "2-1","Column 2": "2-2","Column 3": "2-3","Column 4": "2-4"},{"Column 1": "3-1","Column 2": "3-2","Column 3": "3-3","Column 4": "3-4"},{"Column 1": 4,"Column 2": 5,"Column 3": 6,"Column 4": 7}]' | 
    ConvertFrom-JsonToCsv