TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

JavaScript JSON stringify() Method

JavaScript JSON stringify() Method with examples on javascript json, stringify() method, parse() method, javascript tutorial, features, introduction, examples, variables, javascript array, javascript map, javascript string etc.

<< Back to JAVASCRIPT

JavaScript JSON.stringify() method

The JavaScript JSON.stringify() method converts a JavaScript value to a JSON string. It replaces values if a replacer function is specified or includes only the specified properties if a replacer array is specified.

Syntax

Json.stringify(value[, replacer[, space]])

Parameters

value: The value to convert to a JSON string.

Replacer: A function that alters the behavior of the stringification process. It is optional.

space: A String or Number object that's used to insert white space into the output JSON string for readability purposes. It is optional.

Return value

A JSON string representing the given value.

Browser Support

Chrome Yes
Safari 4
Firefox 3.5
Opera 10.5

JavaScript JSON.stringify() method Examples

Example 1

Let's see an example to convert an object of string to JSON string.

<script>
//JavaScript to illustrate JSON.stringify() method.
var json = { firstName:"ASHU", lastName:"BHATI", studentCode:7 };
var student = JSON.stringify(json);
// expected output: {"firstName":"ASHU","lastName":"BHATI","studentCode":7}
document.write(student); 
</script>
Test it Now

Output:

{"firstName":"ASHU","lastName":"BHATI","studentCode":7}

Example 2

Let's see an example to convert an array object to JSON string.

<script>
//JavaScript to illustrate JSON.stringify() method.
var a = [ "JAVA", "C", "C++", "Python" ];
var Json = JSON.stringify(a);
// expected output: ["JAVA","C","C++","Python"]
document.write(Json);
</script>
Test it Now

Output:

 ["JAVA","C","C++","Python"]
Next TopicJavaScript JSON




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf