Even though JavaScrript Object Notation (JSON) is a newer format than XML, it's simpler, so you'll start by learning about JSON. In this video, Peter first explains JSON's common data types. Then learn about arrays (lists of data), objects (dictionaries for data), and nesting (putting arrays and objects inside of each other).
Strings hold text and are enclosed in single or double quotation marks. Numbers can be either integer, that is, whole numbers, or decimal, and they can be positive, negative, or zero. Booleans can be either true or false. Unlike strings, they do not have quotation marks around them. Finally, you can use Null with no quotation marks to mean nothing. In addition to basic types, JSON has arrays and objects. Arrays are lists. They're enclosed in square brackets and have values with commas in between.
Items in an array do not have to have all the same data type, so you can make strings, numbers, and so on. Here are some examples. The first is an array of numbers. The second is an array of strings. And the third is a mixed array, including a Boolean value and a null value. Objects are what JSON calls dictionaries, meaning that they consist of keys and values where you can look up a value, given a key. Dictionaries are enclosed in curly brackets, and they keys and values are separated by a colon.
Each key and value pair are then separated by commas. Keys and values can be any data type, but string is the most common value for the key. Here's an example of an object that holds values for red, green, and blue. You can see that the first key is the string "red" which has a value of 205. These are separated by a colon. Then there is a comma, and then the next key is "green" with a value of 123. Everything is enclosed in curly brackets. And here's an example that holds some data about a person.
There's a key for first name, last name, and employed, where the names are of type string, and the employee data is of type boolean. Nesting means you've got arrays and objects inside of each other, creating multiple layers of collections. You can put arrays inside of objects, objects inside of arrays, arrays in arrays, and so on. Sometimes a JSON file is one big object with lots of other objects and arrays inside of that one, top-level object.
- The purpose of documentation
- Data types
- Structured data
- Writing JSON and XML
- Documenting one-level JSON responses
- Documenting nested JSON responses
- XML attributes and examples
- Documenting XML
- Structuring data documentation