JSON Files Flashcards

1
Q

JSON Stands for

A

JavaScript Object Notation and was inspired by JavaScript

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Advantages of JSON

A

-Easy to read and write
-Lange independent
-Same syntax as JavaScript Objects
-Store application data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When exchanging data between a browser and a server

A

data can be text, but JSON can be easily converted into objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Jason Uses 2 Structures

A

Name, Value pairs,
which in many languages can be referred to as an object,
struct, or dictionary
An ordered list of values
which in many languages this is referred to as an array or
list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What extension do JSON files have

A

.json extension

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

JSON Values

A

JSON values can be the following:

Strings: Enclosed in double quotes
{“name”: “Gina”}

Numbers
{“age”: 29}

True or False
{“allergies”: true}

Null
{“faxNumber”: null}

Objects
{
“patient”: {“name”: “Gina”, “age”: 29, “city”: “Columbus”}
}

Arrays
{
“patients”: [“Gina”, “Rick”, “ed”, “Russ”]
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

JSON Objects

A

These structures can also be nested. JSON data types cannot be a function, date, or undefined. JSON objects are name/value pairs separated by colons. Pairs are separated by commas and enclosed by curly braces.

{
“storeName”: “Starlight cafe”,
“owner”: “Fred Smith”
}

Arrays are enclosed by square brackets and separated by commas.

“items”: [“banana”, “coffee”, “muffin”]

Arrays can be anything including a collections of objects (nested).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

JavaScript has a built-in function that converts

A

a string into a JavaScript Object

JSON.parse()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When receiving _____ from a ______, it can be used as any JavaScript object. All objects are written as Key/Value pairs and Keys must be ______.

A

data
server
strings

Nesting JSON objects (books 1-4 are nested in books)

myObj = (
“name”: “Gina”,
“age”: 29,
“books”: {
“book1”: “Harry Potter”,
“book2”: “Percy Jackson”,
“book3”: Thrawn”,
“book4”: “Mistborn”
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

JSON Exceptions

A

Dates and functions are not allowed but they can be written as strings and converted later

Date to Convert to a String
var strPerson = ‘ {“name”: “Gina”, “birthday”: “1992-07-05”, “state”: “OH”}’;
var obj = JSON.parse(strPerson);

Parsing Functions
var strPerson = ‘{ “name”: “Gina”, “age”: “function () {return 29;}”, “state”: “OH”}’ ;
var obj = JSON.parse(strPerson) ;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

JSON Versus XML

A

JSON
-Easy to read and understand
-Hierarchical
-No tags needed
-Easy to use with JavaScript
-Lightweight and fast
-Can use arrays

XML
-Easy to read and understand
-Hierarchical
-Requires an XML parser
-Supports more complex data types such as datetime
-Supports namespace

How well did you know this?
1
Not at all
2
3
4
5
Perfectly