Skip to content

Commit

Permalink
Merge pull request #26 from PetriAsi/develop
Browse files Browse the repository at this point in the history
parse json
  • Loading branch information
PetriAsi authored Sep 10, 2021
2 parents 54cf0a5 + 201148e commit d3129fe
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion WilmaPSWorker/Public/Invoke-WPSWPrimusQuery.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function Invoke-WPSWPrimusQuery {

#Parse results and return as parsed psobjects
[Parameter(Mandatory=$true,ParameterSetName="Format results")]
[ValidateSet('xml','csv')]
[ValidateSet('xml','csv','json')]
[string]$ParseResults,

#CSV delimiter
Expand Down Expand Up @@ -165,6 +165,19 @@ function Invoke-WPSWPrimusQuery {
Write-host "Error when trying to parse query results $OutFile to csv:`r$ErrorMessage"
}
}
'json' {
Write-Verbose "Parsing json"
$ft = get-item $Outfile -ErrorAction SilentlyContinue
if ($ft.Length -ne 0 ) {
try {
$parsed = Get-Content -raw $OutFile | ConvertFrom-Json
}
catch {
$ErrorMessage = $_.Exception.Message
Write-host "Error when trying to parse query results $OutFile to json:`r$ErrorMessage"
}
}
}
}
#Return parsed results
$parsed
Expand Down

0 comments on commit d3129fe

Please sign in to comment.