en:xjson
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| en:xjson [2026/06/03 08:56] – created administrator | en:xjson [2026/06/03 09:56] (current) – [XJSON] administrator | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| JSON, JavaScript Object Notation, is a string presentation of a JavaScript object so that JavaScript object can be saved in file or exchange among computers. Although is used in JavaScript, it can also be interpreted in other programming languages. | JSON, JavaScript Object Notation, is a string presentation of a JavaScript object so that JavaScript object can be saved in file or exchange among computers. Although is used in JavaScript, it can also be interpreted in other programming languages. | ||
| - | JSON Data Type Limitation | + | ===== JSON Data Type Limitation |
| The data type used in JSON are null, number, string, boolean, list, and object. The object specified in JSON is only a " | The data type used in JSON are null, number, string, boolean, list, and object. The object specified in JSON is only a " | ||
| Line 12: | Line 12: | ||
| Alternative, | Alternative, | ||
| + | |||
| + | |||
| + | " | ||
| + | " | ||
| + | |||
| + | |||
| + | |||
| + | Another common data type is binary data, which is commonly used for image. However, we can use the same solution for binary data. | ||
| + | |||
| + | ==== String notation of datetime and binary. ==== | ||
| + | |||
| + | The following is a string and object presentasion of DateTime and Binary data. | ||
| + | |||
| + | * The string presentation of datetime, date, time data is " | ||
| + | |||
| + | * The object presentaion of binary data is " | ||
| + | |||
| + | ==== Object notation of datetime and binary. ==== | ||
| + | |||
| + | The object presentation of datetime and binary data use a class specifier, _cls. The available _cls are: | ||
| + | |||
| + | * _cls: datetime, date, or time (datetime) | ||
| + | |||
| + | * _cls: base64, or z85 (binary) | ||
| + | |||
| + | ===== XJSON ===== | ||
| + | |||
| + | There are two other issues in JSON. The first issue is that it must be an object, that is the notation must start with a curly bracket. | ||
| + | |||
| + | Another issue in JSON is that object attributes can either be a number or a string. Thus attributes must be quoted if it is a string. | ||
| + | |||
| + | So iGarment extend the JSON notation in order to make the notation to include more data types, shorter, and easier to use. The extension should also be easy to implement, which is why the data type can be determine by the first character of the data. | ||
| + | |||
| + | The following is a list of data type in corresponding to the first (non-blank) character of a token: | ||
| + | |||
| + | * N: refer to Null | ||
| + | |||
| + | * T/F: refer to boolean | ||
| + | |||
| + | * a digit: refer to a number | ||
| + | |||
| + | * D: refer to a Date | ||
| + | |||
| + | * ": refer to a string (UTF8) and end with another " | ||
| + | |||
| + | * _': refer to a bytes and end with another ' | ||
| + | |||
| + | * [: start of list and must end with ] | ||
| + | |||
| + | Instead of writing a full specification, | ||
| + | |||
| + | The following is an example of an XJSON object, or a key-value pair dictionary. Note that attribute (or dictionary key) does not needed to be quoted, although you can. You cannot use number as attribute. Attribute must be a single word without space in between. | ||
| + | |||
| + | |||
| + | { | ||
| + | feedback : 1, | ||
| + | changeset : { | ||
| + | tablename : " | ||
| + | primary : [ | ||
| + | " | ||
| + | " | ||
| + | ], | ||
| + | fields : [ | ||
| + | " | ||
| + | " | ||
| + | ], | ||
| + | }, | ||
| + | lost: 2300.12- | ||
| + | seed: 0xa78b239 | ||
| + | create_date: | ||
| + | author: N, | ||
| + | locked: F, | ||
| + | icon: _HA09EFJKI===, | ||
| + | } | ||
| + | |||
| + | |||
| + | This is an example for a XJSON for a list instead of an object. It can also be a number or a string too. | ||
| + | |||
| + | [ 1, 2, " | ||
| + | |||
| + | ==== Notes on Boolean ==== | ||
| + | |||
| + | T or True, or TT are the same since we first character already tell the type. Similar to F and False. | ||
| + | |||
| + | ==== Notes on Number ==== | ||
| + | |||
| + | * The sign of a number is put at the end, eg. negative 123 is 123- | ||
| + | |||
| + | * One can use exponential notation, eg. 1.234E4 | ||
| + | |||
| + | * Start a number 0x for hexidecimal. | ||
| + | |||
| + | ==== Notes on DateTime ==== | ||
| + | |||
| + | * The full specification is D[YYYYMMDD][THHMMSS.ZZZ[+HHMM][+TZ]] | ||
| + | |||
| + | * TZ refer to time zone, which is a number | ||
| + | |||
| + | * To specify time. just omit the date but still need to start with ' | ||
| + | |||
| + | ==== Notes on String ==== | ||
| + | |||
| + | * | ||
| + | |||
| + | * You can escape a character with backslash, . The possible escaped characters are \0 \b, \n, \r, \t, \Z, \, ', and ". | ||
| + | |||
| + | ==== Notes on Bytes ==== | ||
| + | |||
| + | You shall put bytes data betwen pair of signle quote if you have space in bytes data. For example _' | ||
| + | |||
| + | ==== Notes on List and Dict ==== | ||
| + | |||
| + | You can leave the last item in a List or Dict blank. Eg [ 1, 2, 3, ] is accepted. So is { a: 1, b: 2, }. But you cannot have an empty item in between. Eg [ 1,,3 ] or { a: , b: 2 }, error. | ||
en/xjson.1780476991.txt.gzip · Last modified: by administrator
