json: catch JsonReaderException

This commit is contained in:
Richard Kuhnt
2018-09-14 18:32:31 +02:00
parent 091ddf503b
commit fb58e92c13

View File

@@ -93,15 +93,21 @@ Function ConvertToPrettyJson {
function json_path([String] $json, [String] $jsonpath, [String] $basename) {
Add-Type -Path "$psscriptroot\..\supporting\validator\bin\Newtonsoft.Json.dll"
$jsonpath = $jsonpath.Replace("`$basename", $basename)
try {
$obj = [Newtonsoft.Json.Linq.JObject]::Parse($json)
$result = $null
} catch [Newtonsoft.Json.JsonReaderException] {
return $null
}
try {
$result = $obj.SelectToken($jsonpath, $true)
return $result.ToString()
} catch [System.Management.Automation.MethodInvocationException] {
write-host -f DarkRed $_
return $null
}
return $result.ToString()
return $null
}
function json_path_legacy([String] $json, [String] $jsonpath, [String] $basename) {