• Open Standard widely used in Web APIs today.
  • Purpose mainly for data serialization.
  • Indentation is completely optional, except for with string literals.
  • MAIN DATA STRUCTURES:
    • Objects/Dictionary
      • Groups of key value pairs.
      • Key must be a string.
      • Value can be objects, numbers, lists, boolean, strings or Null.
    • Lists
      • Ordered sequence of elements.
      • Elements can be same type as object values.
      • Can be objects, numbers, lists, boolean, strings or Null.
  • Object/Dictionary ex.
    • Curly braces and double quotes encapsulate name:value pairs, separated by commas.
      • {“R10″:”4431”, “R20:”2921”, “R30″:3850”}
  • List ex.
    • Same as Python
    • Encapsulated with square brackets and double quotes, separated by commas.
      • [“R1”, “R2”, “R3”]
  • Multi-Line Notation – common, ultimately doesn’t matter because whitespaces do not matter.
  • Using JSON in Python

import json

with open(“example.json”) as f:

data = f.read()

jsonDict = json.loads(data)

for k, v in jsonDict.items():

print( “The key {} uses a {} value.”.format(str(k), str(type(v))) )

  • with open(“example.json”) as f:
    • With open for better exception handling and closes file when done.
  • json.loads(data)
    • What converts imported string (with open <file>) into JSON object/dictionary.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s