How to parse a JSON content

Hallo everybody.

I am trying to shorten a link with API.

The content I get back is the following:

The screenshot show the result in Firefox, but I have it into a KM variable with the GET URL action.

How do I extract the item data / url, i.e. the shortened URL and assign it to a variable?

Thank you and have a nice day.

Hi @tsolignani,
Please post the data you got so that others don't have to type what you got and can test the macro result before uploading to the forum for you.

1 Like

Thank you for your reply. I hadn't thought of that. There you go:


Posted code can be protected from wiki-software display-jumbling if you post it between a pair of backspace triples

  "status_code": 200,
  "status_txt": "OK",
  "data": {
    "url": "",
    "hash": "3slXmJE",
    "global_hash": "3soxCMH",
    "long_url": "",
    "new_hash": 0

and you can access any part of a JSON-formatted variable with some special tokens described at:

manual:JSON [Keyboard Maestro Wiki]

(i.e. the parsing is done for you automatically by Keyboard Maestro)


JSON parts with KM variable subscripts.kmmacros (4.6 KB)


Hi @tsolignani,
When you post data, enclose it with the block coding marks:

put your data here


Like this:

  "data" : {
    "global_hash" : "3soxCMH",
    "hash" : "3slXmJE",
    "long_url" : "https:\/\/\/2021\/12\/21\/sinistro-stradale-dopo-quanto-va-in-prescrizione\/",
    "new_hash" : 0,
    "url" : "https:\/\/\/3slXmJE"
  "status_code" : 200,
  "status_txt" : "OK"

Otherwise, the forum will interpret some signs as markdown syntax and your data is broken, as is shown in your post.

Here is the solution:

JSON - Read JSON Value.kmmacros (6.1 KB)

Click to see screenshot

1 Like

Thank you all for both the solutions and the other advices, as always I got rich answers!

Great community for a marvellouse software.

Have a nice day and a Happy Christmas.



1 Like