JSON static objectS2C Home « Globals « JSON

A static class containing methods for parsing and forming JSON notation, which is an acronym for JavaScript Object Notation.

Description

The JSON format allows us to serialize objects that can be passed across different user platforms in a language dependant way.

  • The JSON global object is a static object which means we cannot instantiate objects of type JSON.
  • The two methods of this class are also static and so we access these using JSON followed by the name of the method we wish to use.

Syntax

Signature Description
JSON.classMethodName()Use a JSON class method.

Parameters

Parameter Description
classMethodNameThe name of the class method we wish to use.

Class Properties

None.

Instance Properties

We cannot instantiate JSON objects and so there are no instance properties.

Class Methods

Class Method Description
parse()Returns a parsed JSON string.
stringify()Converts a value to JSON format.

Instance Methods

We cannot instantiate JSON objects and so there are no instance methods.

Examples



// Store properties in an array.
var jsonMethods = new Array(8);
var jsonMethods = new Array(10);
jsonMethods[0] = 'Parse some data: ';   
jsonMethods[1] = JSON.parse('""'); // Empty String 
jsonMethods[2] = JSON.parse('"A string"'); // A String 
jsonMethods[3] = JSON.parse('[1, 2, 3, 4]'); // Single type array
jsonMethods[4] = JSON.parse('[1, "2", 3, "true"]'); // Multi type array
jsonMethods[5] = JSON.parse('null'); // null
jsonMethods[6] = 'Stringify some data: ';   
jsonMethods[7] = JSON.stringify('""'); // Empty String 
jsonMethods[8] = JSON.stringify('"A string"'); // A String 
jsonMethods[9] = JSON.stringify('[1, 2, 3, 4]'); // Single type array
jsonMethods[10] = JSON.stringify('[1, "2", 3, "true"]'); // Multi type array
jsonMethods[11] = JSON.stringify('null'); // null
alert(jsonMethods);  

Press the button below to action the above code:


Related Tutorials

JavaScript Intermediate Tutorials - Lesson 7 - Object Literals

go to home page Homepage go to top of page Top