JSON: Difference between revisions

From Computer Science Wiki
No edit summary
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 13: Line 13:
</syntaxhighlight>
</syntaxhighlight>


JSON in itself stands for JavaScript Object Notation, which basically means that it is used for Notating Objects, duh. JSON is a JS derivative, it uses very similar if not the exact same syntax as JS (example 1). What JSON is used for, and facilitates on a remarkable level is for serializing and transmitting structured data over a network connection. This is most commonly done to transmit data between a computer and a web application. It facilitates reading the code for the person writing it, but still lets the computer do its work, because it is a more ergonomic version of XML.
JSON (JavaScript Object Notation) is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays (or other serializable values). It is a common data format with diverse uses in electronic data interchange, including that of web applications with servers.


JSON still uses basic data types that most programming languages and formats use (example 2a-f). To show how JSON sets variables with the Basic Data Types, I have made Example 3. To walk you through it all in line 2 and on of the code, the String "Orest" to the variable "firstName", set the Boolean "true" to "isAlive", sets "age" to number "27", makes the array for address, which includes the more Strings, adds object "children", and sets "spouse" to null - basically 0.
JSON is a language-independent data format. It was derived from JavaScript, but many modern programming languages include code to generate and parse JSON-format data. JSON filenames use the extension .json.<ref>https://en.wikipedia.org/wiki/JSON</ref>
 
To use JSON in a JS file, it just requires a quick link to another file (example 4). Any browser supporting ECMAScript fifth edition at minimum is able to parse JSON. Parsing JSON, using the JSON.parse(input) DOM API, however, is not intrinsically safe and should not be performed without ideally both safeguards or relative certainty of the provenance of the JSON data to be parsed. In cases where CORS is not possible, a common workaround minimal safeguard includes the use of JSONP, or JSON with padding, which wraps the JSON data in an additional set of curly braces which renders the output of the parsed JSON as an object and not itself, the inputted JSON, as simultaneously valid and potentially dangerous JavaScript script. (sorry if that's complicated, it is meant to be like that.)
 
<syntaxhighlight>


<syntaxhighlight lang="JavaScript">
Example 1 - String Value Application
Example 1 - String Value Application
JS: { name : 'Orest' }
JS: { name : 'Orest' }
Line 67: Line 64:


</syntaxhighlight>
</syntaxhighlight>
Written and Edited by Orest
== Standards ==
* This topic doesn't cover a specific standard, but it is something you should you know.


== References ==
== References ==

Latest revision as of 21:49, 18 September 2022

Web Science[1]

JSON, it is an open-standard file format that uses human-readable text to transmit data objects consisting of attribute–value pairs and array data types.

{
  "firstName": "Orest",
  "lastName": "Smith",
  "isAlive": true
}

# In the example above, firstname is an attribute, and the value is "Orest".

JSON (JavaScript Object Notation) is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays (or other serializable values). It is a common data format with diverse uses in electronic data interchange, including that of web applications with servers.

JSON is a language-independent data format. It was derived from JavaScript, but many modern programming languages include code to generate and parse JSON-format data. JSON filenames use the extension .json.[2]

Example 1 - String Value Application
JS: { name : 'Orest' }
JSON: { "name" : "Orest" }

Example 2 - Data Types
a. Number
b. String
c. Boolean
d. Array
e. Object
f. Null

Example 3 - Short Biography of a Person in short facts
{
  "firstName": "Orest",
  "lastName": "Smith",
  "isAlive": true,
  "age": 27,
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postalCode": "10021-3100"
  },
  "phoneNumbers": [
    {
      "type": "home",
      "number": "123 654-7809"
    },
    {
      "type": "office",
      "number": "098 765-4321"
    },
    {
      "type": "mobile",
      "number": "123 456-7890"
    }
  ],
  "children": [],
  "spouse": null
}

Example 4 - Parsing JSON in JS
var p = JSON.parse(json_string);

References[edit]