jsonPretty
Turns a value into indented JSON text with the keys in alphabetical order.
Keyboard Maestro: JSONFromDictionary Pretty, JSONFromVariables Pretty
Details #
jsonPretty(value) takes exactly one argument and returns text: the value written as JSON, one item per line with two-space indents, keys sorted, and slashes left unescaped.
Pass a record or a list. Compare jsonText, which writes compact JSON.
Parameters #
Takes 1 argument.
{{ jsonPretty(text) }}
Examples #
jsonPretty(person)→
{
"born" : 1815,
"name" : "Ada"
}| Sample variable | Value |
|---|---|
person | {"born": 1815, "name": "Ada"} |
jsonPretty(variablesJSON("user_"))→
{
"age" : 36,
"name" : "Ada"
}| Sample variable | Value |
|---|---|
user_age | 36 |
user_name | Ada |
Gotchas #
Text is encoded as a JSON string, not parsed:
jsonPretty("{}")gives a quoted string. Parse it first with json.Because keys are sorted, the order won't match how a record was built.