Let me start by singing praises to Peter once again. A few months ago, I learned that you can insert the string "%Variable%SomeVar%" in the variable field of the "Set Variable to Text" action. This was a wonderful discovery which I have used from time to time.
Today I have to sing praises again, because I've learned that you can insert the same string "%Variable%SomeVar%" at the top of the "Set JSON Value X to JSON Y" action. (I wasn't sure if that would work, but it did!) But I'm encountering a strange little problem that might be my fault. Here's the simple action that I'm trying to execute:
My value stored in LocalValue are these four characters: 5555
But when I execute the action, the value assigned are these six characters: "5555"
Why is the KM action adding quotes to the string? How do I stop it from adding those characters when I don't want them? Also, when I try to store the JSON data into a new variable like this: (ignore the greyed-out erroneous data in the bottom of the action: I think that's a bug in the KM Editor, but feel free to try to explain that if you want.)
I end up with the following: (notice the escaped quotes!)
So why is it adding quotes (in the first action)? I guess I can see why it's escaping the quotes in the 2nd action, so that's not my real problem, but where are those double quotes coming from when they never existed in my variable?
If we can get this working, I have a really cool utility that I can release.
Stop the press. I think I found the solution. There are a couple of flags on the cogwheel for that action that appear to deal with the addition of quotation marks. I need to study them now, but that appears to be the solution.
In Strict mode, the result will be a strict JSON objects - strings will be double quoted and appropriately escaped. In Non-Strict mode, string results will be returned as the decoded and de-quoted string.
I guess I have to admit I failed to spot that in the manual. It's there.
Perhaps I can be partially redeemed if I'm still correct about the display glitch at the bottom of the action above. (Those random text strings seem to be coming from my global variables, not my local variables. I think that means this is a bug in the editor.)
If you have any global variables starting with the letter "A", this should illustrate the bug. Notice how all my global variables starting with the letter A are showing up in this action, minus their first letter.
I disagree. I can see why your example works. Did you try my example?
I can explain further. In your example, the editor is showing the variables "local_Alpha" and removing the characters "local_" because that was your "prefix". Your example makes perfect sense to me.
But in my example, the editor is showing GLOBAL variable contents, not Local ones. In my example, the prefix starts with "Local" and there should be no existing local variables when nothing is running. In your example, since you ran your macro, local variables actually exist. But in my example there are no local variables because nothing is running.
So my recommendation is that you try my example to see if you can replicate my problem. You provided a counterexample that works, which is fine, but you should test my example, to confirm that it doesn't work.
Slow/stuck refresh, perhaps? I can reproduce with just Local:
...but it clears as soon as I add to the prefix:
...and yes, I do have globals starting with A:
Interestingly the match seems to completely ignore scope prefix, including any underscores, until I add the extra character. The __AllCaps matched variable, for example, is actually named Global__AllCaps.
It's Editor UI behaviour, so that's difficult. But try this, adding/removing a character to/from Local in the token:
Is it really 5555 or are there some non-numeric characters?
Because:
5555 is valid JSON.
"XYZ" is valid JSON.
But XYZ is not valid JSON.
And in my testing, 5555 as input to the Set JSON Value action does not quote 5555 regardless of whether it is strict mode or not.
There is no bug in this.
For each local variable the editor knows about that has a prefix of LocalJ, the editor is including it in the JSON that it is displaying. And they obviously have no value in the editor (since they are local variables). In your case, you have macros that use the variables:
LocalJoinedValue
LocalJSON
LocalJSON1
LocalJSONPath
LocalJunk
And the editor is dutifully giving you what you would get from the action if the editor ran it right now.
The result in this case would not match what you would get if you ran it in the engine, since the known local variables with prefix LocalJ would be different and they might have values.