Languages
[Edit]
EN

JavaScript - serialize object to json

12 points
Created by:
Lani-Skinner
468

In JavaScript script it is possible to serialize object to json in following way.

1. JSON.stringify method example

// ONLINE-RUNNER:browser;

var studentObject = {
    name: 'John',
    age: 25,
    todos: [
        'Sleeping',
        'Lectures',
        'Classes',
        'Shopping'
    ]
}

var studentJson = JSON.stringify(studentObject);

console.log(studentJson);

Note: JSON.stringify method has been introduced in ES5.

See also

  1. JavaScript - deserialize json to object 

JavaScript - JSON

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join