JSON
What is JSON and where it is used in Altogic?
Since Altogic exposes RESTful APIs for your application services and JSON is a key data format in RESTFul APIs, it is important to introduce JSON briefly.
JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is mainly used storing data in document databases and transporting data between different applications, primarily between a server and web applications. JSON is also frequently used in RESTFul APIs to provide data in request and response bodies. Below is an example JSON document summarizing a menu of a restaurant.
1
{
2
"name": "Pizza & Pasta",
3
"type": "Italian",
4
"address": {
5
"street": "235 Clark St",
6
"city": "Chicago",
7
"state": "IL",
8
"zipcode": 60645
9
},
10
"averageRaging": 4.5,
11
"menu": {
12
"appetizers": [
13
{
14
"name": "Bruschetta",
15
"description": "Tomatoes, garlic, fresh basil, virgin olive oil, mozzarella and parmesan",
16
"price": 8.75
17
},
18
{
19
"name": "Fried Ravioli",
20
"description": "Breaded ricotta-stuffed ravioli served with marinara",
21
"price": 7.5
22
}
23
],
24
"pizza": [
25
{
26
"name": "Meat",
27
"description": "Sausage, pepperoni, bacon, ham & extra cheese",
28
"price": 17
29
},
30
{
31
"name": "Veggie",
32
"description": "Garlic, tomatoes, spinach, black olives & mushrooms",
33
"price": 15
34
}
35
]
36
}
37
}
Copied!
JSON supports the following two data structures;
  • Collection of name/value pairs
  • An ordered list of values − It includes arrays, lists, or sequences, etc.
A name/value pair consists of a field name (in double quotes), followed by a colon, followed by a value. So in the below example, the name is "firstName," and the value is "John."
1
"firstName": "John"
Copied!
Please note that that for text values, you need to put them between double quotes; however, for numbers, boolean values, or null values, you do not need double-quotes.
1
"age": 24
Copied!
In JSON, values must be one of the following data types:
  • String - Strings in JSON must be written in double quotes
1
{ "fistName": "John" }
Copied!
  • Number - Numbers in JSON must be an integer or a floating-point
1
{ "age": 25 }
Copied!
  • Object (JSON object) - Values in JSON can be objects. However, objects as values in JSON must follow the same rules as JSON objects.
1
{
2
"address": {
3
"street": "235 Clark St",
4
"city": "Chicago",
5
"state": "IL",
6
"zipcode": 60645
7
}
8
}
Copied!
  • Array - Values in JSON can be arrays. Array values are provided between []
1
{ "restaurantTypes": [ "Italian", "Indian", "Japaneese" ] }
Copied!
  • Boolean - Either true or false value
1
{ "onsale": true}
Copied!
  • Null - Empty value or no value
1
{ "middleName": null}
Copied!
Copy link