JavaScript Object Notation
1) It is a Structured format for representing data for storing and exchanging data
1.1) It is a data model – has its own structure like an XML
In NoSQL Databases: MongoDB (which we will study later) the data (Documents) are stored as JSON objects
APIs return data in JSON format
1) Also, optionally, as XML documents or CSVs
1.1) XML is old. CSVs can be broken or corrupted, and we do not have the schema
1.2) JSONs are the newest and most secure data structure with Faster Transmission speeds
JSON Syntax
Data is in Key/Value pairs
Data is separated by commas
Curly braces hold objects
1) In this context an object is a set of Key/Value pairs separated by commas
Square brackets hold arrays
1) An array is a sequence of values which can be accessed randomly, i.e., without having to traverse the previous values
2) E.G., You can get to the 5th position in an array without having to go through the
previous values in the sequence.
JSON Key/Value Pairs
Example
JSON Exercise
Represent the following information in a well-formed JSON object:
Vera BigShot is the President of BigDeal, Inc. She has two pets: a dog named Woof who is three years old and a cat named Meow who is ten years old. She has three homes, one in New York, NY; one in Palm Beach, FL; and one in Flagstaff, AZ. She is not married. Her hobbies are golfing and tormenting students. She was born on June 10, 1995 in Oakland, California.
Note: Represent every fact about her in separate key/value pairs. So don’t put ‘Palm Beach, FL’ as one value — break it up into a city and a state value.
Answer:
Vera BigShot is the President of BigDeal, Inc. She has two pets: a dog named Woof who is three years old and a cat named Meow who is ten years old. She has three homes, one in New York, NY; one in Palm Beach, FL; and one in Flagstaff, AZ. She is not married. Her hobbies are golfing and tormenting students. She was born on June 10, 1995 in Oakland, California.
Comments