Get all JSON values with one KM action?

I'm just exploring the JSON support in Keyboard Maestro.

I want to get all values of a JSON variable. I don't know how to do it easily without having to use the loop action.

Sample JSON (I use only 2 elements for example. A real JSON array could contain many more than 2):

    "id" : 12345,
    "name" : "John Smith",
    "id" : 67890,
    "name" : "Mark Smith",

I want to get all the [id]s:


Right now, the only way I know of is to loop through all data.

First, get the count of the JSON variable:
Var = %JSONValue%Local__JSON[0]%

Then, loop through it:
For i = 1, i ++, Var

Is there an easier way to do it?

In Shell script, I can use this:

cat | jq '.[].id'

# [] will get all elements in the JSON array, and .id will get all the [id]s.

It's OK if KM cannot do it with one action yet. The shell script serves my need. I just want to explore the JSON function in KM.

1 Like