Passing JSON to a Macro

Given I have in the main macro

Local__Cautious = 1 and Local__Verbose = 0

how would I create a variable

`JSON_parameters =
{
"cautious":1,
"verbose":0
}

which after passing to Execute Macro with Parameter unpack the JSON to

Local__Cautious = 1 and Local__Verbose = 0

?

Found

which creates

1 Like

If you have the time, could you please post a short but complete example of this sort of packing and unpacking? I have just looked at the Wiki page for the %JSONFromVariables% token but it makes little sense to me. :thinking:

JSON Packing and Unpacking.kmmacros (4.1 KB)

Example steps

Setup the variables

Pack the variables into JSON by changing Prefix given with the %JSONFromVariables%Prefix% token to the common prefix of the variables you want as JSON keys

Reality check.
Should see {"A":"1","B":"2","C":"3")

Unpack the JSON keys in %Variable%Local__JSON% to variables starting with the prefix Out__

Reality Output Check

Example Run



Here's a bare minimum demo for packing, passing by parameter, and unpacking. Run "Main", enter your values, and "Submacro" will display them. I've set "Submacro" run async and started it with a pause to prove that, despite having the same names, these are being passed by parameter and aren't available through submacro "inheritance"...

Parameters by JSON Macros.kmmacros (5.0 KB)

1 Like

@csmu @Nige_S Thank you both!

1 Like