Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Boolean functions

$boolean

$boolean(arg) converts a value to a Boolean. The same rules apply wherever JSONata needs a Boolean: in predicates, with and, or, ?: and in conditions.

ArgumentResult
a Booleanunchanged
a stringfalse if empty
a numberfalse if 0
nullfalse
an arraytrue if any item converts to true
an objectfalse if empty
a functionfalse
nothingnothing (false in conditions)
[$boolean("0"), $boolean(0), $boolean([0, ""]), $boolean([0, 1]), $boolean({})]
=> [true, false, false, true, false]

$not

$not(arg) converts arg to a Boolean and negates it.

[$not(true), $not(""), $not([1])]
=> [false, true, false]
input: library.json
library.books[$not("Kernighan" in authors)].title
=> ["Structure and Interpretation of Computer Programs", "Compilers: Principles, Techniques, and Tools"]

$exists

$exists(arg) returns true if arg produces a value, even null or false, and false if it produces nothing.

input: address.json
[$exists(Other.Misc), $exists(Other.Nothing), $exists(Phone[type = 'fax'])]
=> [true, false, false]

Adapted from the JSONata documentation (MIT license).