Search code examples
krl

In KRL, how do I detect if a variable is an array or hash?


In KRL, I'd like to detect whether a variable is an array or hash so that I know if I need to use the decode or encode operator on it. Is that possible?

I'd like to do something like this:

 my_var = var.is_array => var.decode() | my_var

Solution

  • Update The best way to do this is with the typeof() operator. This is new since the answer, but with the early interpretation of variables, the old way listed in the answer will no longer work.

    Another useful operator for examining your data is isnull()

    myHash.typeof() => "hash"
    myArray.typeof() => "array"
    ...