I\'ve looked on wikipedia and Googled it and read the official documentation, but I still haven\'t got to the point where I really understand what JSON is, and why I\'d use
Understanding JSON
JSON is just a text format that most REST APIs use to return their data. Another common format is XML, but XML is quite a bit more verbose.
Here’s a small example of JSON:
// JSON object
{
"name": "John",
"age": 20
}
// JSON array
[
{
"name": "John",
"age": 20
},
{
"name": "Peter",
"age": 22
}
]
Notice that the snippet starts with a brace {
, which indicates an object. JSON can also start as an array, which uses the square bracket [
symbol to signify the start of the array. JSON needs to be properly formatted, so all beginning {
and [
symbols need to have their ending symbols: }
and ]
.
JSON can contain object or array. An object in JSON is wrapped inside the braces { … }
, while an array is wrapped inside square brackets [ … ]
.
JSON structures data by key-value. Key is always a string, but value could be anything (String, number, JSON object, JSON array…). This will affect the way we parse JSON in the next steps.