Back to Home
$jsonExists
$jsonExists checks if a key exists in the current JSON
object. Returns true if it does, false if it
does not.
Syntax
$jsonExists[Key;...]
Key: one or more keys forming the path to check.
Returns empty if no $jsonParse or
$jsonSet was called, or $jsonClear was
called.
What happens
$jsonParseloads the JSON object into memory.-
$jsonExistschecks whether the key at the given path exists. - Returns
trueorfalse.
Example 1: Check a key
$nomention
$jsonParse[{"username":"Zubariel"}]
$jsonExists[username]
$jsonExists[tag]
What happens:
-
$jsonParseloads the object which hasusernamebut notag. $jsonExists[username]returnstrue.$jsonExists[tag]returnsfalse.
Output:
true
false
Example 2: Use inside a condition
$nomention
$jsonParse[{"role":"admin"}]
$if[$jsonExists[role]==true]
Role: $json[role]
$else
No role set.
$endif
What happens:
$jsonParseloads the object.-
$jsonExists[role]returnstrue, so the$ifblock runs. $json[role]returnsadmin.
Output:
Role: admin
Common uses
-
Validating before reading: confirm a key exists
before calling
$jsonon it - Conditional logic: branch behaviour based on whether a field is present
- Array checks: verify a nested key exists before appending to it
See also
- $json: to read the value once confirmed it exists
- $jsonUnset: to remove a key after checking it exists