VerifyJSON
Verifies if the supplied JSON string is valid and optionally verifies against a provided schema. The script utilizes Powershell's Test-JSON cmdlet.
- Type
- powershell
- Pack
- CommonScripts
Source
. $PSScriptRoot\CommonServerPowerShell.ps1
function Main() {
$json = $demisto.Args()["json"]
$schema = $demisto.Args()["schema"]
if ($schema) {
$res = Test-Json -Json $json -Schema $schema -ErrorAction SilentlyContinue -ErrorVariable err
}
else {
$res = Test-Json -Json $json -ErrorAction SilentlyContinue -ErrorVariable err
}
$outputs = @{VerifyJSON = @{Result = $res } }
if ($res) {
ReturnOutputs "Verify JSON completed successfully" -Outputs $outputs | Out-Null
return
}
else {
$errMsg = "$($err[0].Exception.Message)"
if ($err[0].Exception.InnerException.Message) {
$errMsg += " $($err[0].Exception.InnerException.Message)"
}
if ($err[0].ErrorDetails.Message) {
$errMsg += " $($err[0].ErrorDetails.Message)"
}
ReturnError $errMsg $err $outputs | Out-Null
}
}
# Execute Main when not in Tests
if ($MyInvocation.ScriptName -notlike "*.Tests.ps1") {
Main
}
README
Verifies if the supplied JSON string is valid and optionally verifies against a provided schema. The script utilizes Powershell’s Test-JSON cmdlet.
Script Data
| Name | Description |
|---|---|
| Script Type | powershell |
| Tags | JSON, Utility |
| Cortex XSOAR Version | 5.5.0 |
Inputs
| Argument Name | Description |
|---|---|
| json | JSON string to verfiy. |
| schema | Optional schema against which to validate the JSON input. |
Outputs
| Path | Description | Type |
|---|---|---|
| VerifyJSON.Result | Whether the passed JSON was verified. | boolean |
Script Example
!VerifyJSON json={"alert_id":"695b3238-05d6-4934-86f5-9fff3201aeb0"}
Context Example
{
"VerifyJSON": {
"Result": true
}
}
Human Readable Output
Verify JSON completed successfully