JSON: Difference between revisions
From DataFlex Wiki
Jump to navigationJump to search
m
Change
m (Correction & addition) |
m (Change) |
||
Line 31: | Line 31: | ||
JSON values can be one of six data-types - four "primitive" and two "compound": | JSON values can be one of six data-types - four "primitive" and two "compound": | ||
====Primitive:==== | |||
*'''Strings''', which, like names, must be quoted with <u>double-quote</u> characters: <font color="blue">"value"</font> | *'''Strings''', which, like names, must be quoted with <u>double-quote</u> characters: <font color="blue">"value"</font> | ||
*'''Numbers''', which can be simple integers, or decimal values, or exponentiated (using either "e" or "E") and may be negative: | *'''Numbers''', which can be simple integers, or decimal values, or exponentiated (using either "e" or "E") and may be negative: | ||
Line 45: | Line 45: | ||
*'''Null''', which is simply represented by <font color="blue">null</font> (unquoted) | *'''Null''', which is simply represented by <font color="blue">null</font> (unquoted) | ||
====Compound:==== | |||
*'''Objects''', which are enclosed in '''{''' ... '''}''' characters and generally contain additional name/value pairs: <font color="blue">{"surname":"Peat", "forename":"Mike", "age":21, "is male":true, "salary":null}</font> | *'''Objects''', which are enclosed in '''{''' ... '''}''' characters and generally contain additional name/value pairs: <font color="blue">{"surname":"Peat", "forename":"Mike", "age":21, "is male":true, "salary":null}</font> | ||
*'''Arrays''', which are enclosed in '''[''' ... ''']''' characters and are made up of values separated by commas: <font color="blue">[5, "Mike", false, 14.70912, null, -5.34108e9]</font> | *'''Arrays''', which are enclosed in '''[''' ... ''']''' characters and are made up of values separated by commas: <font color="blue">[5, "Mike", false, 14.70912, null, -5.34108e9]</font> | ||
Whitespace is irrelevant <u>outside</u> of double-quotes (although both names and string values may contain whitespace). Because of this, JSON may be formatted for easier human-readability (''prettified'') with spaces and line breaks: | ==Prettifying== | ||
Whitespace is irrelevant <u>outside</u> of double-quotes (although both names and string values may contain whitespace). Because of this, JSON may be formatted for easier human-readability (''prettified'') with spaces and line breaks, so: | |||
<font color="blue">{"first name":"Mike","last name":"Peat","age":21,"is male":true,"salary":null,"address":{"house":22,"street":"Acacia Avenue","town":"Dullsville","county":"Midhamptonshire"},"test scores":[56,87,19,11,70,64]}</font>. | |||
Is the same, from a machine standpoint, as the rather more human-readable: | |||
<font color="blue">{ | <font color="blue">{ | ||
Line 66: | Line 71: | ||
}</font> | }</font> | ||
Which is | Which is only slightly less compact "on the wire" (by around 25 bytes). | ||
==JSON in DataFlex== | ==JSON in DataFlex== |