JSON Subroutines (getValueFromKey, Add New Key Value Pair, updateJSON

Hey,

I built 3 subroutines for handling typical JSONS on a single JSON object.
The top macro is an example of how you'd could use it
For it to work, you'd have to download the three subroutines below.
Hope you find these helpful.

UpdateJSON will only update values for keys that exists. To create a new key, use add new key value pair and then you can update that with UpdateJSON.

BTW, I just noticed that the javascript box on each subroutines is titled "Copy to Clipboard". Yeah it doesnt copy to clipboard. It just the name of my previously used Javascript action.

Your welcome.

Ben

JSON.kmmacros (2.7 KB)

updateJSON

updateJSON.kmmacros (2.7 KB)

JSON - getValueFromKey

JSON - getValueFromKey.kmmacros (2.4 KB)

JSON - add new key value pair

JSON - add new key value pair.kmmacros (2.6 KB)

Not simpler to use the %JSONValue% token ?

token:JSONValue [Keyboard Maestro Wiki]

Value for JSON key.kmmacros (2.5 KB)

Perhaps for that one alone.
I beileve a consistent, easy to use interface is more important than simplicity.
If you had to do that with your approach for the other 2 features i provided, consistency may go out the window.

As you are very much aware, this approach is reusable and they dont need to worry about syntax.

eg. %JSONValue%local_JSON.name%

For the other case:

action:Set JSON Value [Keyboard Maestro Wiki]