Skip to content

Commit

Permalink
parse json
Browse files Browse the repository at this point in the history
  • Loading branch information
PetriAsi committed Sep 10, 2021
1 parent 6297f79 commit 201148e
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 201148e

Please sign in to comment.