janbaer
2/27/2013 - 6:55 AM

Convert CSV to Json with powershell

Convert CSV to Json with powershell

param
(
    [string] $inputFile,
    [string] $outputFile
)
 
if (($inputFile -eq $null) -or ($outputFile -eq $null)) {
    "usage: convert_csv_to_json.ps1 [inputFile] [outputFile]"
    return;
}
elseif ((Test-Path $inputFile) -eq $false) {
    "The file $inputFile doesnt exists!"
    return;
}
 
Get-Content -path $inputFile | ConvertFrom-Csv -Delimiter ';' | ConvertTo-Json | Out-File $outputFile