How to Create JSON String in JavaScript? Last Updated : 06 May, 2024 Comments Improve Suggest changes Like Article Like Report JSON strings are widely used for data interchange between a server and a client, or between different parts of a software system. So converting objects to JSON strings is very important for good client-server communication. Below are the following approaches to creating a JSON string: Table of Content Using JSON.stringify( ) methodUsing Template literalsUsing JSON.stringify( ) methodWe can directly convert a Javascript object to a JSON string using the JSON.stringify( ) method where we pass the object as an argument. The output will be a string following the JSON notation. Example: In this example, we will create a Javascript object and convert it into a JSON string. JavaScript // Creating a JavaScript object let obj = new Object(); obj.name = 'Mohit'; obj.department = 'CSE(Data Science)'; obj.age = 20; // Converting JS object to JSON string let json_string = JSON.stringify(obj); console.log(json_string); Output{"name":"Mohit","department":"CSE(Data Science)","age":20} Using Template literalsTemplate literals provide a more readable and dynamic way to construct JSON strings compared to traditional string concatenation.The template literal syntax, enclosed by backticks (`), allows for multiline strings and interpolation of variables using ${}. Example: This example shows the use of the above-explained approach. JavaScript let name = "Mohit"; let department = "CSD"; let age = 20; let JSON_string = `{ "name": "${name}", "department": "${department}", "age": "${age}" }`; console.log(JSON_string); Output{ "name": "Mohit", "department": "CSD", "age": "20" } Comment More infoAdvertise with us Next Article How to Create JSON String in JavaScript? M mohithsharmajf3o Follow Improve Article Tags : JavaScript Web Technologies JSON JavaScript-Questions Similar Reads How to Convert JSON to string in JavaScript ? In this article, we are going to learn the conversion of JSON to string in JavaScript. Converting JSON to a string in JavaScript means serializing a JavaScript object or data structure represented in JSON format into a textual JSON string for data storage or transmission.Several methods can be used 3 min read How to Convert String to JSON in JavaScript? In JavaScript, converting a string to JSON is important for handling data interchangeably between server and client, parsing external API responses, and storing structured data in applications. Below are the approaches to converting string to JSON in JavaScript: Table of Content Using JSON.parse()Us 2 min read How to Print a String in JavaScript ? In JavaScript, printing a string means displaying the contents of a string variable or literal to the console, webpage, or any other output medium. Strings are a fundamental data type in JavaScript, representing sequences of characters enclosed within single ('') or double ("") quotes. Table of Cont 2 min read How to Concatenate Strings in JavaScript? Here are the various methods to concatenate strings in JavaScript1. Using Template Literals (Template Strings)Template literals (introduced in ES6) provide a simple way to concatenate strings. With template literals, you can embed expressions inside a string using ${} syntax. This method makes the c 3 min read How to modify a string in JavaScript ? JavaScript strings are used for storing and manipulating text. It can contain zero or more characters within quotes and its indexing starts with 0. Strings are defined as an array of characters. In Javascript, we can also convert strings to a Character array. Representing a String: 1. Using double 3 min read Like