Set JSON Value—How Do You Set a Value to an Integer?

The following:

Keyboard Maestro Export

Creates the following JSON, with 1 as a string:

{
  "item" : [
    {
      "integer" : "1",
      "text" : "text A"
    }
  ]
}

With native KM actions, can I set this value to 1 as an integer?

{
  "item" : [
    {
      "integer" : 1,
      "text" : "text A"
    }
  ]
}

Might have to know more about the context.

You can directly set the value of a KM variable to:

{
  "item" : [
    {
      "integer" : 1,
      "text" : "text A"
    }
  ]
}

But Keyboard Maestro only has one data-type (String) so when you retrieve the value, its up to you to interpret that 1 as an integer – by applying calc functions etc to it.

@ComplexPoint, thanks for the information.

I'm working on a subroutine macro that gathers attributes of selected items within the Finder. I plan to return the array of attributes using a JSON string.

That I knew, but I was hoping that there might be a function or token to address this situation.

Yes, not difficult, but I was hoping to simplify if it was unnecessary.

If you wanted to detect and report the types of values, perhaps returning them in key value tuples {type: "Number", value: 2} etc
you could do some preprocessing in JavaScript for automation to get a 'typeof' type name for the value, and make use of it in KM actions.

1 Like