stringify()  JSON  class methodS2C Home  « Globals « 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

go to home page Homepage go to top of page Top