How to Create JSON String in JavaScript? Last Updated : 23 Jul, 2025 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 Interview Preparation For Software Developers M mohithsharmajf3o Follow Improve Article Tags : JavaScript Web Technologies JSON JavaScript-Questions Similar Reads Interview PreparationInterview Preparation For Software DevelopersMust Coding Questions - Company-wise Must Do Coding Questions - Topic-wiseCompany-wise Practice ProblemsCompany PreparationCompetitive ProgrammingSoftware Design-PatternsCompany-wise Interview ExperienceExperienced - Interview ExperiencesInternship - Interview ExperiencesPractice @GeeksforgeeksProblem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More...Data StructuresArraysLinked ListStackQueueBinary TreeBinary Search TreeHeapHashingGraphAdvance Data StructuresMatrixStringAll Data StructuresAlgorithmsAnalysis of AlgorithmsSearching AlgorithmsSorting AlgorithmsPattern SearchingGeometric AlgorithmsMathematical AlgorithmsRandomized AlgorithmsGreedy AlgorithmsDynamic ProgrammingDivide & ConquerBacktrackingBranch & BoundAll AlgorithmsProgramming LanguagesCC++JavaPythonC#Go LangSQLPHPScalaPerlKotlinWeb TechnologiesHTMLCSSJavaScriptBootstrapTailwind CSSAngularJSReactJSjQueryNodeJSPHPWeb DesignWeb BrowserFile FormatsComputer Science SubjectsOperating SystemsDBMSComputer NetworkComputer Organization & ArchitectureTOCCompiler DesignDigital Elec. & Logic DesignSoftware EngineeringEngineering MathematicsData Science & MLComplete Data Science CourseData Science TutorialMachine Learning TutorialDeep Learning TutorialNLP TutorialMachine Learning ProjectsData Analysis TutorialTutorial LibraryPython TutorialDjango TutorialPandas TutorialKivy TutorialTkinter TutorialOpenCV TutorialSelenium TutorialGATE CSGATE CS NotesGate CornerPrevious Year GATE PapersLast Minute Notes (LMNs)Important Topic For GATE CSGATE CoursePrevious Year Paper: CS exams Like