$abs

$abs operator helps you in calculating absolute value in an expression. You can use this in any Expression Object.

for e.g.

If you want to calculate change in temperature

  • change from 12 degree celcius to 18 degree celcius

  • change from 18 degree celcius to 12 degree celcius

Both of these should result in 6 degree change but using simple $subtract would give result as 6 and -6 which is not a valid response.

Syntax

{
    "$abs":<value | expr>
}

Properties

FieldDescriptionRequired

<value | expr>

The <value> is any valid number.

The <expr> expression can be any valid expression as long as it resolves to a number.

It can also be a Magical Autocomplete.

true

Returns

number - The result of $abs operation

Examples

Basic example

{
    "$abs": -5
}

The above expression returns 6.0

With Nested Expressions

{
    "$abs": { "$subtract": [1, 2] }
}

The above expression calculates the nested expression, return -1 in its place and then the outer $abs expression returns 1 overall.

With Magical Autocomplete

Let's say we have declared a variable temp in our API flow, which has a value of -8 currently.

{
    "$abs":"$.variables.temp"
}

The above expression would resolve to a result of 8

Last updated