Search within TutorialsPark

Javascript JSON: Introduction


Using JSON to exchange and parse data over a network.


Javascript JSON: Introduction

Earlier, only XML was used for transmitting structured data, then can standard of JavaScript Object Notation(JSON)

JSON Specification was first specified by Douglas Crockford as IETF RFC 4627 in the year 2006. JSON is a very strict subset of JavaScript, it uses several JavaScript patterns to represent structured data.

JSON is not a programming language, it is not a part of JavaScript even though they share syntax.

JSON was originally related to JavaScript, but it is language independent and is used widely with C++, Python, Java, Ruby , Perl and so on.

JSON format is mostly used for serialization and transmitting structured data using Ajax.


Javascript JSON: Syntax

The JSON syntax is used to represent three types of values:

Simple Values : All kinds of numbers, strings, Booleans and null can be represented in JSON using the Syntax same as JavaScript

Objects : Ordered datatypes such as key-value pairs are represented by objects. Values may be primitive or complex in nature.

Arrays : An array is used to represent an ordered list of values which can be accessed using a numeric index value. The values can be of any type, simple values , objects and sometime even other arrays.

JSON has no variables, functions or object instances, it used to represent only structured data.


Javascript JSON Syntax: Simple Values

JSON can represent all types of simple values, it can be used to represent numbers , strings boolean etc.

JSON strings are different from Javascript strings in a sense that JSON strings must be within double quotes strictly, or else it is invalid.

Example: JSON Syntax Simple Values.


JavaScript JSON Syntax: Objects

In JSON, objects are represented using a slightly different object literal notation, it uses a quoted property format.

There are two prominent differences for JavaScript syntax:

  • There is no variable declaration.
  • There is no trailing semicolon at the end of declaration.

You can also use complex objects, i.e objects within objects. But names in JSON must always be double-quoted.

Example: JavaScript JSON : Objects


Javascript JSON Syntax: Arrays

An array is another complex type in JSON, arrays are represented in JSON using arrat literal notation from JavaScript.

Arrays and object can be used together in order to represent more complex data collections.

Example: JavaScript JSON - Arrays.