mirror of
https://github.com/ScoopInstaller/Scoop.git
synced 2025-12-12 02:56:03 +00:00
json: catch JsonReaderException
This commit is contained in:
12
lib/json.ps1
12
lib/json.ps1
@@ -93,15 +93,21 @@ Function ConvertToPrettyJson {
|
|||||||
function json_path([String] $json, [String] $jsonpath, [String] $basename) {
|
function json_path([String] $json, [String] $jsonpath, [String] $basename) {
|
||||||
Add-Type -Path "$psscriptroot\..\supporting\validator\bin\Newtonsoft.Json.dll"
|
Add-Type -Path "$psscriptroot\..\supporting\validator\bin\Newtonsoft.Json.dll"
|
||||||
$jsonpath = $jsonpath.Replace("`$basename", $basename)
|
$jsonpath = $jsonpath.Replace("`$basename", $basename)
|
||||||
$obj = [Newtonsoft.Json.Linq.JObject]::Parse($json)
|
try {
|
||||||
$result = $null
|
$obj = [Newtonsoft.Json.Linq.JObject]::Parse($json)
|
||||||
|
} catch [Newtonsoft.Json.JsonReaderException] {
|
||||||
|
return $null
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$result = $obj.SelectToken($jsonpath, $true)
|
$result = $obj.SelectToken($jsonpath, $true)
|
||||||
|
return $result.ToString()
|
||||||
} catch [System.Management.Automation.MethodInvocationException] {
|
} catch [System.Management.Automation.MethodInvocationException] {
|
||||||
write-host -f DarkRed $_
|
write-host -f DarkRed $_
|
||||||
return $null
|
return $null
|
||||||
}
|
}
|
||||||
return $result.ToString()
|
|
||||||
|
return $null
|
||||||
}
|
}
|
||||||
|
|
||||||
function json_path_legacy([String] $json, [String] $jsonpath, [String] $basename) {
|
function json_path_legacy([String] $json, [String] $jsonpath, [String] $basename) {
|
||||||
|
|||||||
Reference in New Issue
Block a user