Scalar functions

Conversion functions

Function NameDescription
tobool()Converts input to boolean (signed 8-bit) representation.
todatetime()Converts input to datetime scalar.
todouble(), toreal()Converts the input to a value of type real. todouble() and toreal() are synonyms.
tostring()Converts input to a string representation.
totimespan()Converts input to timespan scalar.
tohex()Converts input to a hexadecimal string.
tolong()Converts input to long (signed 64-bit) number representation.
dynamic_to_json()Converts a scalar value of type dynamic to a canonical string representation.
isbool()Returns a value of true or false if the expression value is passed.

tobool()

Converts input to boolean (signed 8-bit) representation.

Arguments

  • Expr: Expression that will be converted to boolean.

Returns

  • If conversion is successful, result will be a boolean. If conversion isn't successful, result will be false

Example

tobool(Expr)

toboolean(Expr) (alias)
tobool("true") == true
  • Result:
{
  "conversion_function": true
}

todatetime()

Converts input to datetime scalar.

Arguments

  • Expr: Expression that will be converted to datetime.

Returns

If the conversion is successful, the result will be a datetime value. Else, the result will be false.

Example

todatetime(Expr)
todatetime("2022-11-13")
  • Result
{
  "boo": "2022-11-13T00:00:00Z"
}

todouble(), toreal()

Converts the input to a value of type real. (todouble() is an alternative word to toreal())

Arguments

  • Expr: An expression whose value will be converted to a value of type real.

Returns

If conversion is successful, the result is a value of type real. If conversion is not successful, the result returns false.

Example

toreal(Expr)todouble(Expr)
toreal("1567") == 1567
  • Result:
{
  "conversion_function": true
}

tostring()

Converts input to a string representation.

Arguments

  • Expr: Expression that will be converted to string.

Returns

If the Expression value is non-null, the result will be a string representation of the Expression. If the Expression value is null, the result will be an empty string.

Example

tostring(Expr)
tostring(axiom) == "axiom"
  • Result:
{
  "conversion_function": "axiom"
}

totimespan

Converts input to timespan scalar.

Arguments

  • Expr: Expression that will be converted to timespan.

Returns

If conversion is successful, result will be a timespan value. Else, result will be false.

Example

totimespan(Expr)
  • Result
{
  "conversion_function": "1.998µs"
}

tohex()

Converts input to a hexadecimal string.

Arguments

  • Expr: int or long value that will be converted to a hex string. Other types are not supported.

Returns

If conversion is successful, result will be a string value. If conversion is not successful, result will be false.

Example

tohex(value)
tohex(-546) == 'fffffffffffffdde'
tohex(546) == '222'
  • Result:
{
  "conversion_function": "fffffffffffffdde"
}

tolong()

Converts input to long (signed 64-bit) number representation.

Arguments

  • Expr: Expression that will be converted to long.

Returns

If conversion is successful, result will be a long number. If conversion is not successful, result will be false.

Example

tolong(Expr)
tolong("241") == 241
  • Result:
{
  "conversion_function": 241
}

dynamic_to_json()

Converts a scalar value of type dynamic to a canonical string representation.

Arguments

  • dynamic input (EXpr): The function accepts one argument.

Returns

Returns a canonical representation of the input as a value of type string, according to the following rules:

  • If the input is a scalar value of type other than dynamic, the output is the application of tostring() to that value.

  • If the input in an array of values, the output is composed of the characters [, ,, and ] interspersed with the canonical representation described here of each array element.

  • If the input is a property bag, the output is composed of the characters {, ,, and } interspersed with the colon (:)-delimited name/value pairs of the properties. The pairs are sorted by the names, and the values are in the canonical representation described here of each array element.

Examples

dynamic_to_json(dynamic)
['sample-http-logs']
| project conversion_function = dynamic_to_json(dynamic([1,2,3]))
  • Result:
{
  "conversion_function": "[1,2,3]"
}

isbool()

Returns a value of true or false if the expression value is passed.

Arguments

  • Expr: The function accepts one argument. The variable of expression to be evaluated.

Returns

Returns true if expression value is a bool, false otherwise.

Example

isbool(expression)
isbool("pow") == false
  • Result:
{
  "conversion_function": false
}

Was this page helpful?