User Tools

Site Tools


manual:JSON

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revision Both sides next revision
manual:JSON [2019/06/24 00:33]
peternlewis created
manual:JSON [2021/10/04 03:25]
peternlewis
Line 1: Line 1:
 ====== JSON ====== ====== JSON ======
  
-Keyboard Maestro ​(v9.0+) ​includes comprehensive support for [[https://​json.org|JSON]] (JavaScript Object Notation), which is a formalized lightweight data-interchange format.+Keyboard Maestro includes comprehensive support for [[https://​json.org|JSON]] (JavaScript Object Notation), which is a formalized lightweight data-interchange format.
  
 JSON objects consist of one of: JSON objects consist of one of:
Line 30: Line 30:
 * “.” followed by the field name.  Field names are trimmed of leading or trailing whitespace - if your object field names can start or end with white space, you need to use the `{ field name }` notation. * “.” followed by the field name.  Field names are trimmed of leading or trailing whitespace - if your object field names can start or end with white space, you need to use the `{ field name }` notation.
  
-Array indices are 1-based. ​ The 0 index of an array access will return the count of the number of entries in the array.+Array indices are 1-based.  Negative indices count from the end of the array.  The 0 index of an array access will return the count of the number of entries ​in the array. ​ When evaluating the index, the context sensitive COUNT() function will return the number of elements ​in the array.
  
 Keyboard Maestro will use arrays and dictionaries more or less interchangeably,​ so: Keyboard Maestro will use arrays and dictionaries more or less interchangeably,​ so:
Line 38: Line 38:
 * J{3} * J{3}
  
-will all return the third element of an array, or the dictionary value for key “3”.+will all return the third element of an array, or the dictionary value for key “3”.  And important distinction is that the first one is a numeric calculation,​ the second one is plain text, and the third one is token text.
  
 ===== Pretty, Compact and Strict Flags ===== ===== Pretty, Compact and Strict Flags =====
Line 51: Line 51:
     {"​a":​3,"​b":​null}     {"​a":​3,"​b":​null}
  
-whereas the result of %JSONValuePretty%J%` will be:+whereas the result of `%JSONValuePretty%J%` will be:
  
     {     {
Line 58: Line 58:
     }     }
  
-The exact indentation should not be assumed, it might be any number ​fo spaces or tabs.+The exact indentation should not be assumed, it might be any number ​of spaces or tabs.
  
 The Strict flag relates only to JSON results that are trivial JSON strings, eg JSON `"​result"​`. The Strict flag relates only to JSON results that are trivial JSON strings, eg JSON `"​result"​`.
Line 78: Line 78:
 The default result format is Compact, Non-Strict. The default result format is Compact, Non-Strict.
  
 +===== Use =====
  
 +There are [[:​Actions|actions]] to set dictionaries or variables from JSON containers, as well as an [[:action: Set_JSON_Value|action]] to set a field within a JSON object to a specified value.
  
 ===== Notes ===== ===== Notes =====
Line 84: Line 86:
 JSON objects must be properly legal to be processed. ​ In particular keys to objects must be strings, which means strings must be quoted with double quotes. `{ a : 3 }` is not valid, it must be `{ "​a"​ : 3 }`. JSON objects must be properly legal to be processed. ​ In particular keys to objects must be strings, which means strings must be quoted with double quotes. `{ a : 3 }` is not valid, it must be `{ "​a"​ : 3 }`.
  
-Although `3` and `"​a"​` are technically legal JSON, in cases of ambiguity, Keyboard Maestro will not consider a variable to contain JSON unless it is a container, ie an array or dictionary, which starts (without any leading white space) with a `{` or `[`, and ends with a matching bracket followed by optional white space. +Although `3` and `"​a"​` are technically legal JSON, in Non-Strict mode with cases of ambiguity, Keyboard Maestro will not consider a value or variable to contain JSON unless it is a container, ie an array or dictionary, which starts (without any leading white space) with a `{` or `[`, and ends with a matching bracket followed by optional white space.
  
manual/JSON.txt · Last modified: 2024/04/21 22:23 by peternlewis