What is difference between JSON.parse() and JSON.stringify() Methods in JavaScript ?
Last Updated :
28 Apr, 2025
JSON.parse() converts JSON strings to JavaScript objects, while JSON.stringify() converts JavaScript objects to JSON strings. JavaScript utilizes JSON for data interchange between servers and web pages. These methods enable easy data manipulation and transport in web development.
JSON.parse() Method
JSON.parse() converts a JSON string to a JavaScript object. It accepts a JSON string as input. It must be in string format when sending data to a web server locally. It's useful for storing data in local storage as browsers store data in key-value pairs.
Syntax
JSON.parse( string, function )
Example: In this example, we define a constant myInfo containing JSON-like data. It's parsed into an object Obj. The code then logs the values of Name and Age from Obj. The resulting output would be GFG and 22, respectively.
JavaScript
const myInfo = `{
"Name": "GFG",
"Age":22,
"Department" : "Computer Science and Engineering",
"Year": "3rd"
}`
const Obj = JSON.parse(myInfo);
console.log(Obj.Name)
console.log(Obj.Age)
JSON.stringify() Method
JSON.stringify() converts JavaScript objects into JSON strings, accepting a single object argument. It contrasts JSON.parse(). With replacer parameters, logic on key-value pairs is feasible. Date formats aren't allowed in JSON; thus, they should be included as strings.
Syntax
JSON.stringify(value, replacer, space);
Example: This example we converts the JavaScript object myInfo into a JSON string using JSON.stringify(). It then logs the resulting JSON string, which represents the object's data.
JavaScript
const myInfo = {
Name: "GFG",
Age:22,
Department : "Computer Science and Engineering",
Year: "3rd"
}
const Obj = JSON.stringify(myInfo);
console.log(Obj)
Output{"Name":"GFG","Age":22,"Department":"Computer Science and Engineering","Year":"3rd"}
Difference Between JSON.stringify() Method & JSON.parse() Method
JSON.parse() | JSON.stringify() |
---|
Converts JSON string to JavaScript object. | Converts JavaScript object to JSON string. |
The string must be wrapped in double quotes. example: “String”.
| No need to wrap the string in double quotes.
|
Accepts only one argument, the JSON string. | Accepts only one argument, the JavaScript object. |
Useful for parsing data received from servers. | Useful for converting JavaScript objects for transmission. |
Can handle JSON with nested objects and arrays. | Preserves data types, including numbers, strings, arrays, and objects. |
Can't include functions or undefined values. | Includes all enumerable properties, excluding functions and undefined values. |
Handles dates as strings; must be converted. | Allows optional replacer function to customize output or filter properties. |
Similar Reads
Difference Between Variables and Objects in JavaScript The variables and objects are fundamental concepts but they serve different purposes. The Variables are used to store data values while objects are used to group related data and functions into a single entity. JavaScript VariableA variable in JavaScript is a named container that stores a value. It
2 min read
Difference between Object.keys() and Object.entries() methods in JavaScript Object.keys() and Object.entries() are methods in JavaScript used to iterate over the properties of an object. They differ in how they provide access to object properties: Object.keys() returns an array of a given object's own enumerable property names, while Object.entries() returns an array of a g
2 min read
What is the difference between â(â¦);â and â{â¦}â in ReactJS ? When you write JavaScript, you can use either the "(â¦)" or "{â¦}" pattern to define objects. In ReactJS, (...); and {...} are used in different contexts and have different purposes, and are used to denote different types of code structures. What is "(â¦);" in React JS ?In ReactJS, (...); is used to de
5 min read
Difference between GET and POST request in Vanilla JavaScript In this article, we will learn about the GET & POST request method in vanilla Javascript, & will also understand these 2 methods through the examples. GET and POST is two different types of HTTP request methods. HTTP protocol supports many methods to transfer data from the server or perform
3 min read
Difference between Node.js and JavaScript JavaScript and Node.js are both crucial in modern web development, but they serve different purposes and are used in different environments. JavaScript is a programming language primarily used for client-side web development, while Node is a runtime environment that allows JavaScript to be executed
3 min read
How to parse JSON object using JSON.stringify() in JavaScript ? In this article, we will see how to parse a JSON object using the JSON.stringify function. The JSON.stringify() function is used for parsing JSON objects or converting them to strings, in both JavaScript and jQuery. We only need to pass the object as an argument to JSON.stringify() function. Syntax:
2 min read