apoc.convert.toBoolean

Function APOC Core Deprecated

apoc.convert.toBoolean(value) | tries it’s best to convert the value to a boolean

Signature

apoc.convert.toBoolean(bool :: ANY?) :: (BOOLEAN?)

Input parameters

Name Type Default

bool

ANY?

null

Usage Examples

Convert number 1 to boolean
RETURN apoc.convert.toBoolean(1) AS output;
Table 1. Results
Output

true

Convert number 0 to boolean
RETURN apoc.convert.toBoolean(0) AS output;
Table 2. Results
Output

false

This function has been deprecated and will be removed in version 5.0. The functionality is replaced by the Neo4j functions toBoolean(value) and the more permissive toBooleanOrNull(value). The Neo4j functions do not have exactly the same behavior as the APOC ones - the following table is intended to assist migration by highlighting the differences:

Table 3. Migration Path to toBoolean() / toBooleanOrNull()
Input apoc.convert.toBoolean toBoolean() toBooleanOrNull()

null

false [1]

null

null

true

true

true

true

"true"

true

true

true

""

false

null

null

1

true

true

true

0

false

false

false

1.0

true [2]

Error

null

{a:'a'} [3]

true

Error

null

"no" [4]

false

null

null

"yes" [4]

true

null

null

datetime("2000-01-01T00:00:00.000+0000") [3]

true

Error

null

Point({x:0.0, y:0.0}) [3]

true

Error

null

Node [3]

true

Error

null

Relationship [3]

true

Error

null

Path ()-[]-() [3]

true

Error

null


1. Use x IS NOT NULL for this behavior in Neo4j
2. Use toBoolean(toInteger()) for this behaviour in Neo4j
3. There is no Neo4j equivalent toBoolean for these types
4. Strings other than true and false are not recognised by the Neo4j functions