stringify  JSON  class method JS Home  <<  JS Reference  <<  JSON  <<  stringify

Description

Converts a value to JSON format.

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

Syntax

Signature Description
JSON.stringify(someText[, transformer [, space]])Converts a value to JSON format.

Parameters

Parameter Description
someTextThe value you wish to parse to JSON format.
transformerComputed value transformed prior to return:
  • If a function transforms value and properties prior to return.
  • If an array specifies property set for conversion.
spaceResult will be a 'pretty-printed' formatted string.

Examples



// Store properties in an array.
function HomeOwner(firstName,lastName) {  
  this.firstName=firstName;  
  this.lastName=lastName;  
}  
var ownerList = new Array(3);

ownerList[0] = new HomeOwner('Barney','Magrew'); 
ownerList[1] = new HomeOwner('Manny','Simon'); 
ownerList[2] = new HomeOwner('Arnie','Padrew'); 

alert('The list of objects we created: ' + ownerList);
alert('The list of objects we created Stringified: ' 
      + JSON.stringify(ownerList));  

Press the button below to action the above code:

Related Tutorials

JavaScript Intermediate Tutorials - Lesson 7 - Object Literals



JavaScript Basics

JavaScript Basics

JavaScript Intermediate

JavaScript Intermediate

JavaScript Advanced

JavaScript Advanced

JavaScript Reference

JavaScript Entities

Globals

JSON

Class Properties
None.
Instance Properties
None.
Class Methods
parse()
stringify()
Instance Methods Getters
None.
Instance Methods Setters
None.

Statements

Operators