- Print
- DarkLight
- PDF
Purpose of the article
Javascript Object Notation (JSON) is used primarily in web technologies to:
- creating configuration files (e.g. to configure workflows in the Cooperlink application)
- data storage (e.g. in so-called document or noSQL databases)
- data transfer (e.g. structure of data exchanged as part of a REST API)
- or the exploitation of data in a database
This article explains the basics of scoring.
Javascript Object Notation (JSON)
As the name suggests, JSON is a notation, not a language. This means that there are no instructions that can be interpreted by a computer or software. JSON allows you to create data structures in the same way as XML (HTML is a language that is interpreted by web browsers).
Structure
The basic structure of a JSON file is as follows:
{
"numericKey": numericValue,
"textKey": "textValue",
"booleanKey": true,
"nestedKey":
{
"subPropertyKey": value
},
"simpleArrayKey": [1, 2, 3],
"complexArrayKey": [
{
"subPropertyKey1": value
},
{
"subPropertyKey2": value
}
]
}
The information contained between curcly-braces is called objects, that is, collections or structures of heterogeneous data elements. The data is called properties and can be of type:
- simple with key-value pair syntax: "key": value
- or complex (i.e. combinations of simple collections).
Properties are separated by a comma except when they end a collection.
Property keys are free. But they are interpreted by the software that uses them. A protocol must therefore be defined to establish an interpretable JSON code.
Property values can be of different types: numeric, text (in this case make use of quotation marks ""), boolean, ...
Properties can be nested , that is, they can themselves contain a collection of properties delimited by braces { }.
The information enclosed in square brackets [ ] is an array. An array is a collection of similar data items stored in contiguous memory locations, either properties or objects.
Media
JSON notation can be used through different media:
- In a text file that is usually given the .json extension (e.g. config.json)
- In a REST API call (e.g. https://demo-api.cooperlink.io/tasks - Requires prior authentication on https://demo.cooperlink.io)
- In a database
Tools
There are various free tools to manipulate JSON data with visual aids (colorization of properties in particular) and syntax checking.
- Online
- Desktop
- Notepad++