parse()  JSON  class methodS2C Home  « Globals « JSON « parse()

Description

Returns a parsed JSON string.

  • Like all class methods parse() should be used on the class rather than an instance of the class.

Syntax

Signature Description
JSON.parse(someText[, transformer])Returns a parsed JSON string.

Parameters

Parameter Description
someTextThe value you wish to parse to JSON format.
transformerComputed value transformed prior to return.

Examples



// Store properties in an array.
var parseMethod = new Array(10);
parseMethod[0] = 'Parse some data: ';   
parseMethod[1] = JSON.parse('""'); // Empty String  
parseMethod[2] = JSON.parse('"A string"'); // A String 
parseMethod[3] = JSON.parse('[1, 2, 3, 4]'); // Single type array
parseMethod[4] = JSON.parse('[1, "2", 3, "true"]'); // Multi type array
parseMethod[5] = JSON.parse('null'); // null
parseMethod[6] = 'Parse a function with arguments: ';   
parseMethod[7] = JSON.parse('{"Square": 3}', 
                 function(a, b) { if (a === "") 
                 return b; return b * b; }); // func
parseMethod[8] = 'Stringify parsed function: ';   
parseMethod[9] = JSON.stringify(parseMethod[7]); // value of func
alert(parseMethod);  

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