JSON: Difference between revisions

548 bytes added ,  17 June 2021
m (Correction & addition)
 
(One intermediate revision by one other user not shown)
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''':
====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''':
====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 the same, from a machine standpoint, as the rather less human-readable:
Which is only slightly less compact "on the wire" (by around 25 bytes).
<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>.


==JSON in DataFlex==
==JSON in DataFlex==
Line 89: Line 93:


* [http://starzen.com/products/utility-libraries/json-library/ Starzen JSON Library]
* [http://starzen.com/products/utility-libraries/json-library/ Starzen JSON Library]
*[https://support.dataaccess.com/Forums/showthread.php?65503-cJsonPath-class cJsonPath class] - Mike Peat, 6th Feb 2020. Easily get either objects or values from deep inside pretty complex JSON data.
*[https://support.dataaccess.com/Forums/showthread.php/65493-JsonConfig-pkg JsonConfig.pkg] - Mike Peat, 5th Feb 2020. A little singleton object-package which can read in a JSON configuration file and then allows you to read various settings out of it.


[[Category:REST]]
[[Category:REST]]
[[Category:JSON]]
[[Category:JSON]]
[[Category:System Integration]]
[[Category:System Integration]]