Skip to content

JSON Concepts – Oracle Cloud Orchestration

JSON (JavaScript Object Notation) is a lightweight data-interchange format. This simple language is used a lot in Oracle Cloud and many other new Oracle products like SOA and Oracle 12c. It is easy for humans to read and write this language. It is easy also for machines to parse and generate. JSON is a text format that is completely language independent which make JSON an ideal data-interchange language. The file type for JSON files is “.json”

JSON is real-time server-to-browser communication without using browser plugins such as Flash or Java applets. Almost all new web browser supports JSON.

Simple example of JSON syntax:

var test = {"age" : "27", "gender" : "male"};

This creates an object that we access using the variable test. By enclosing the variable’s value in curly braces, we’re indicating that the value is an object. Inside the object, we can declare any number of properties using a "name": "value" pairing, separated by commas. To access the information stored in test, for example, to access information about age, we could use the following snippets:

 document.write('test_case is ' test.age); // Output: test_case is 27

JSON syntax is derived from JavaScript object notation syntax:

  • Data is in name/value pairs ( example “age” : “27”)
  • Data is separated by commas as shown above
  • Curly braces hold objects as shown above
  • Square brackets hold arrays

An example of Array is like below:

var employees = [
    { "firstName":"mike", "lastName":"smith" },
    { "firstName":"Aria", "lastName":"jones" },
    { "firstName":"Pete","lastName": "lords" }
];

 

In JSON, values must be one of the following data types:

  • a string
  • a number
  • an object (JSON object)
  • an array
  • a boolean
  • null

JSON values cannot be one of the following data types:

  • a function
  • a date
  • undefined

Not having a “date” as value is a drawback of JSON. If you need to include a date, write it as a string.

Remember that JSON is text, and we can convert any JavaScript object into JSON, and send JSON to the server and in return can also convert any JSON received from the server into JavaScript objects. This way we can work with the data as JavaScript objects, with no complicated parsing and translations.

Like XML, it is human-readable, platform independent, and enjoys a wide availability of implementations.  Difference between JSON and XML is that JSON is quicker to read and write, it doesn’t use end tag and can use arrays. Also XML has to be parsed with an XML parser. JSON can be parsed by a standard JavaScript function.

For more information refer to www.json.org

 

Brijesh Gogia
Leave a Reply