Set Variable to items in JSON array

Hopefully someone can help me identify why this is not working as expected.
I have reduced the macro down to the basics.
I have a JSON file and I want to retrieve the members listed in the Team[] key array.
Everything works except the Local__team variable is blank.
I have also tried with same result.
%JSONValue%JSONV.value.fields.Team[{%Variable%Local__count%}]%

If I use the following, I do get the last value in the array, but I want to to get all values.
I need to get them individually for the next phase.
%JSONValue%JSONV.value.fields.Team[COUNT()]%

I found a workaround using
%JSONValue%JSONV.value.fields.Team[COUNT() - Local__count]%
and modifying the Local__count start and test conditions.

Would prefer to get it working without using COUNT() for use in other cases
unrelated to this test.

Set Variable to Text Action (v10.0.2)

Set Variable to Text.kmactions (521 B)

Keyboard Maestro Export

Sorry, first time using the share to forum option in KM.
I think this is now a complete macro.

Get Items from Array in JSON Macro (v10.0.2)

Get Items from Array in JSON.kmmacros (7.1 KB)

Forget the Local__count - 1 and is>= 0
I modified these when I went to the COUNT() option.
I was using just Local__count and is> 0

Believe it or not, the answer is to specify Local__count without the %Variable% wrapper. Like this:

2022-02-02_12-09-15

Don't ask me why - this makes no sense to me. But it does work.

Are you sure ?

Between the percentage bookends lies the JSON name-space.

If

  • JSONV
  • value
  • fields
  • Team

are all bound to values in that name-space, should we be surprised that Local_count is also bound ?

(Dot-notation and square-bracket affixes are, of course, interchangeable synonyms in JS. Wherever we can write the one, we can also write the other).

posted by mistake.

Yes, I'm sure that at the time I wrote that, it didn't make any sense to me.

1 Like

Thanks Dan.
That works.
Probably the one combination I didn't try.

1 Like

Continuing forward using this information I am stuck at the next step.
I am trying to avoid using a bunch of if tests which is my back up plan.

I now have a list of variables Local_Team A, etc which will be 0 or 1
depending if they are in the array.

So far so good.

Using the above variables, I launch a checklist prompt with the already included
Teams checked allowing to change check/uncheck each team in the list.
This will set the variables to the new 0/1 setting.

Using a For action, I am trying to loop over the variables and capture the ones that are set to 1.

Here is what I have.
The trouble is in setting the Local_team variable.
Not sure if I can do it this way using this to access the values in each Local__Team x variable.
%Variable%Local__{%Variable%Local__teamResults%}%
I can use a variable to create part of the name of a new (or existing) variable,
but I can't figure out how use the same concept to retrieve the value of the variable.

I may just have to resort to many if statements, but thought I would check here first.

If Action Variable Tokens copy Macro (v10.0.2)

If Action Variable Tokens copy.kmmacros (11 KB)