Variable as start of JSON path

I want to read a read a JSON variable with %JSONValue%. But depending on which Application is currently active I want to read a different JSON. I thought I'd be able to do something like this:

%JSONValue%{%Variable%Global_App%}.Windows%.

But that doesn't work. I can use variables anywhere in the JSON path except for the very first item. For instance the following works:
%JSONValue%myJSON{%Variable%Global_Window%}%

But I can't figure out a way to START a path with a variable. I do this all the time with Dictionaries to choose which dictionary I want to use based on variables. There must be some way to do this with JSON that I just can't figure out. Any help would be appreciated!

It may be worth bearing in mind that JSON property name processing begins with the first item of JS syntax, such as [ or . Before that, we simply have the name of a Keyboard Maestro variable.

To nest a %Variable% token inside the scope of another token, (e.g. %JSONValue%), you should be able, as described in the Wiki entry on action:Set Variable to Text – Dynamic Variables, to :

  1. Compose a relevant string escaped with doubled percentage characters, and then
  2. use a Filter action with the Process Tokens option to obtain a value from the expression.

Roughly this kind of pattern:

Run-time names in JSONValue expressions.kmmacros (4.7 KB)

1 Like

THANK YOU!!! I had missed the Dynamic Variables in the wiki and none of my searches led me there!

This is fantastic and I'll use it in many other things.

1 Like