How Do I List All Key-Value Pairs in JSON String?

How Do I List All Key-Value Pairs in JSON String?


I have studied this KM Wiki article: JSONValue token.
But it does NOT provide any examples on how to use this token in a For Each loop to list all of the key-value pairs.

I've tried a lot of different syntax, but this is what I have now:
%Local__Field%: %JSONValue%Instance__SetRecordJSON.%%Local__Field%%)%

where Local__Field is the For Each loop variable.

I also searched the forum but did not find anything.

I'm trying to get a list like this:

Size:		22,33
Position:	1001,201
Area:		601
Weight:	    5

Here is what the below macro gets:


MACRO:   TEST List All Key-Values in JSON String

-~~~ VER: 1.0    2021-05-27 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

TEST List All Key-Values in JSON String .kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.

The JSON user manual section documents the format of JSON paths in Keyboard Maestro.

You can use tokens within the {} because they can be balanced, and so the % within the {} is not available to close the JSONValue.

Generally you cannot use tokens within a .field because the % would close the JSONValue.

So use:

%Local__Field%:	%JSONValue%Instance__SetRecordJSON{%Variable%Local__Field%}%

Thanks. That worked.

I did read that page, but found this confusing:

I think a simpler example where you don't overload the use of "fieldname" would be very helpful.