Cypher toBoolean Function

toBoolean() converts a string value to a boolean value.

Syntax: toBoolean(expression)

Returns: A Boolean.

Arguments

NameDescription
expressionA Numeric Expression.

Example

RETURN toBoolean('TRUE')

The value return will be a boolean after converting the expression to boolean. In this case, the string ‘TRUE’ will be converted to boolean true.

Note– ‘TRUE’ is not the same as true. ‘TRUE’ is a string whereas true is a boolean.

Considerations

  • toBoolean(null) returns null.
  • If expression is a boolean value, it will be returned unchanged.
  • If the parsing fails, null will be returned.

Example

RETURN toBoolean("FALSE")

Returns the following Result

toBoolean("FALSE")
false

Example

RETURN toBoolean("false")

Returns the following Result

toBoolean("false")
false

Note– The value returned is will be same irrespective of whether the string is in upper-case, lower-case or mixed-case.

Example

RETURN toBoolean(TRUE)

Returns the following Result

toBoolean(TRUE)
true

Example

RETURN toBoolean("Some Random String")

Returns the following Result

toBoolean("Some Random String")
null

Note– If any value other “TRUE” or “FALSE”(case in-sensitive) is passed as a String, then the parsing fails and null is returned.

Example

RETURN toBoolean(0)

Returns the following Result

toBoolean(0)
ERROR Neo.ClientError.Statement.SyntaxError

Note– If any value other than String or Boolean is passed, it raises an error.

Example

RETURN toBoolean(null)

Returns the following Result

toBoolean(null)
null

Learn More