JSON and BSON Data Models

Outline

JSON ? What is it ?

  • Java Script Object Notation (JSON) is a light–weight data interchange format
  • It is based on a subset of the JavaScript Programming
  • Language Standard ECMA-262 3rd Edition - December 1999 JSON is built on two structures:
    • A collection of name:value pairs - object
    • An ordered list of values - array
  • Object is an unordered set of name:value pairs
      
      {"first name": "James"}
      {"city":"Sydney", "street":"Victoria", "building number":25}
      {"number":"25", "isOdd ?":true, "nothing":null}
      
      { }
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, CSCI235 Database Systems, Autumn 2026

JSON ? What is it ?

  • Value is either a string or a number or true or false or null or an object or an array
      
      {"single quote": "\'", "back slash":"\\",
       "forward slash":"\/", "line feed":"\u000A" }
      
      {"fraction":0.25, "true":true, "false":false, "nothing": null}
      
      {"full name": {"first name":"James",
                     "initials":null,
                     "last name":"Bond"},
       "number":"007"}
      
      {"colours":["red", "green", "blue"]}
      
      {"numbers":[10, 20, 30, 40, 50]}
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, CSCI235 Database Systems, Autumn 2026

JSON ? What is it ?

  • Array is a sequence of values
      
      {"2dim array":[ [11,12,13,14],
                      [21,22,23,24],
                      [31,32,33,34] ]}
      
      {"array of objects": [ {"name":"James Bond"},
                             {"name":"Harry Potter"},
                             {"name":"Robin Hood"} ] }
      
      {"array of truth":[true, false, true, true]}
      
      {"array of nothing":[null, null, null, null, null]}
      
      {"empty array":[ ]}
      
      {"array of varieties":[1, "one", true, ["a", "b", "c"]]}
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, CSCI235 Database Systems, Autumn 2026

JSON and BSON Data Models

Outline

BSON ? What is it ?

  • Binary JSON (BSON) is a computer data interchange format used mainly as a data storage and network transfer format in the MongoDB database system
  • BSON is a is a binary encoded serialization of JSON-like documents (objects)
  • BSON includes the extensions not in JSON that allow for representation of data types
  • For example BSON has a Date type and a BinData type
  • The common data types include: null, boolean, number, string, array, embedded document(object)
  • The new data types include: date, regular expression, object id, binary data, code
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, CSCI235 Database Systems, Autumn 2026

BSON ? What is it ?

    • {"nothing":null}
      
      {"truth":false}
      
      {"pi":3.14}
      
      {"int":NumberInt("345")}
      
      {"long":NumberLong("1234567890987654321")}
      
      {"greeting":"Hello !"}
      
      {"pattern":/(Hi|Hello)!/}
      
      {"date":new Date("2016-10-17")}
      
      {"array of varieties":[1, "one", true, ["a", "b", "c"]]}
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, CSCI235 Database Systems, Autumn 2026

BSON ? What is it ?

    • 
      {"_id":ObjectId()}
      
      {"code":function(){ /* ... */ }}
      
      {"Double":124.56}
      
      {"timestamp":Timestamp(1234567,0)}
      
      {"timestamp":Timestamp()}
      
      {"maxkey":{"$maxKey": 1} }
      
      {"minkey":{"$minKey" : 1} }
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, CSCI235 Database Systems, Autumn 2026

BSON ? What is it ?

  • Every document (object) in BSON must have an "_id" key !
  • "_id" key's value can be of any type
  • A default value of "_id" key is ObjectId()
  • In a collection of documents (objects) every document (object) must have a unique value for "_id"
  • If a document has no "_id" key then when it is inserted into a collection "_id" key is automatically added to the document
       
      {"_id":ObjectId()}
       
      {"_id":ObjectId("507f191e810c19729de860ea") }
       
      {"_id": NumberInt(1234567) }
       
      {"_id": "1234567 CSCI235 01-AUG-2021" }
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, CSCI235 Database Systems, Autumn 2026

References