JSON – Introduction



JSON – Introduction

0 0


JSON-Introduction-Part-I

Introduction to JSON - Part I

On Github SUNY-Albany-CCI-LearningEncounters / JSON-Introduction-Part-I

JSON

Introduction

Created by Luis Ibanez

JSON Introduction by Luis Ibanez is licensed under a Creative Commons by Attribution 4.0 License Apache 2.0 License

JSON

Introduction

  • JavaScript
  • Object
  • Notation

JSON

is

a lightweight

data interchange format

JSON

is

language independent

JSON

is

self-describing

Let's write

some JSON

Launch Vim from the command line prompt

to create a new file

vim movie.json

Type in the file the following

{
  "Title" : "The Matrix",
  "Year"  : "1999",
  "Rated" : "R"
}

Save the file and quit the editor

JSON uses the

colon symbol ":"

to separate the property key from its value

"key" : "value"

The key

is

a question

The value

is

the answer

Reopen the file with Vim and add more fields

"Runtime" : "136 min",
"Released"  : "31 Mar 1999"

Save the file and quit the editor

Sometimes

the question

has multiple answers

Therefore

the value

is an array

Let's consider

the actors

in a movie

Reopen the file with Vim and add more fields

"Actors" : [
  "Keanu Reeves",
  "Laurence Fishburne",
  "Carrie-Anne Moss",
  "Hugo Weaving"
],

Save the file and quit the editor

Note the use of

square brackets []

around the array

Sometimes

the question

has a composite answers

Let's consider

an address

Type in a new file the following

{
  "Name" : "Kermit",
  "Address"  : "21 Sesame Street, Boston MA, 12345"
}

Save the file and quit the editor

Edit the file and rewrite it as

{
  "Name" : "Kermit",
  "Address" : {
    "Street number" : "21",
    "Street name"   : "Sesame Street",
    "City" : "Boston",
    "State" : "MA",
    "ZIP" : "12345"
    }
}

Save the file and quit the editor

Even the street

question

can be decomposed

Edit the file and rewrite it as

{
  "Name" : "Kermit",
  "Address" : {
    "Street" : {
      "Number" : "21",
      "Name" : "Sesame Street"
      },
    "City" : "Boston",
    "State" : "MA",
    "ZIP" : "12345"
    }
}

Answers

can be nested

to any level

Using blocks with

curly brackets {}

for composite answers

Using blocks with

square brackets []

for array answers

Breath!

Smile!