@peternlewis I just discovered that the prefix in %JSONFromVariables%prefix% is case-sensitive.
Why? Variable names aren't case-sensitive. This is especially troublesome when I want to write code to get local variables. People use prefixes like "local" or "Local" or "LOCAL".
I'll have to write some JXA to deal with this for now.
It's the prefix we're talking about, and that isn't used in the JSON key itself. There are also no case-sensitivity issues with the token, since KM variables aren't case-sensitive.
But the token is problematic in other ways -- consider the following:
...where our two separate KM variables are reduced to a single JSON key/value pair.
And while you can see from the above that it treats the space character at the end of the prefix as optional, it doesn't do the same for the (commonly used) underscore.
So I think I'd only use this token for variables whose names I was in control of...
I hear you. In my case, I want to call a sub-macro, but have it still have access to my local variables, and even be able to update them.
So I pass local variables in a JSON string. The sub-macro does whatever it does with them, even changing them. The sub-macro returns the updated local variables in a JSON string, and I use "Set Variables to JSON" with an empty prefix to update them in the calling macro.
It seems to work OK, now that I'm using JXA to get the local variables.
This is the code I'm using:
const result = {};
Object.keys(kmvar).forEach(key => {
if (key.toLowerCase().startsWith("local"))
result[key] = kmvar[key];
});
return JSON.stringify(result, null, 2);
(And yes, I could do this with a "reduce", but to my old-school mind, this is easier to understand.)
It's in an "Execute JavaScript with Automation" action with "Modern Syntax" and "Include all variables".
lowering in the JS is much cleaner than the way I was looking at -- re-casing the variable name itself. It works, but I'd worry about persistence and side-effects:
That said, I think Dan is right, variables are case insensitive and thus the prefix should be case insensitive, but the result will be JSON, which will use the case sensitive name of the remainder of the variable.
Variables do have a case preserving name, but even so it's problematic.
So given the issues, despite thinking it should probably be case insensitive, I'm going to leave it alone and just document it.