All current browsers have native JSON support built in. So as long as you're not dealing with prehistoric browsers like IE6/7 you can do it just as easily as that:
var j = {
"name": "binchen"
};
console.log(JSON.stringify(j));
Answer from Andris on Stack Overflow Top answer 1 of 16
2059
All current browsers have native JSON support built in. So as long as you're not dealing with prehistoric browsers like IE6/7 you can do it just as easily as that:
var j = {
"name": "binchen"
};
console.log(JSON.stringify(j));
2 of 16
124
With JSON.stringify() found in json2.js or native in most modern browsers.
JSON.stringify(value, replacer, space) value any JavaScript value, usually an object or array. replacer an optional parameter that determines how object values are stringified for objects. It can be a function or an array of strings. space an optional parameter that specifies the indentation of nested structures. If it is omitted, the text will be packed without extra whitespace. If it is a number, it will specify the number of spaces to indent at each level. If it is a string (such as "\t" or " "), it contains the characters used to indent at each level.
Top answer 1 of 16
2127
JSON.parse(jsonString) is a pure JavaScript approach so long as you can guarantee a reasonably modern browser.
2 of 16
907
The jQuery method is now deprecated. Use this method instead:
let jsonObject = JSON.parse(jsonString);
Original answer using deprecated jQuery functionality:
If you're using jQuery just use:
jQuery.parseJSON( jsonString );
It's exactly what you're looking for (see the jQuery documentation).
Videos
06:27
How to Parse JSON Data in JavaScript | Learn JSON.parse() to Read ...
06:25
How to Parse JSON Data in JavaScript | Convert JSON Strings to ...
05:04
What is JSON.stringify in JavaScript | Convert JavaScript Objects ...
12:26
Convert Object to JSON String - Leetcode 2633 - JavaScript 30-Day ...
02:32
Quick Guide: JavaScript JSON Parsing & Stringifying in 2 Minutes ...
Convert JS Object to JSON string - JavaScript Interview Questions ...
JavaScript.info
javascript.info › tutorial › the javascript language › data types
JSON methods, toJSON
The JSON (JavaScript Object Notation) is a general format to represent values and objects. It is described as in RFC 4627 standard. Initially it was made for JavaScript, but many other languages have libraries to handle it as well. So it’s easy to use JSON for data exchange when the client uses JavaScript and the server is written on Ruby/PHP/Java/Whatever. ... JSON.stringify to convert objects into JSON.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › JSON › stringify
JSON.stringify() - JavaScript | MDN
If space is anything other than ... representing the given value, or undefined. ... A BigInt value is encountered. JSON.stringify() converts a value to the JSON notation that the value represents....
W3Schools
w3schools.com › js › js_json_parse.asp
JSON.parse()
A common use of JSON is to exchange data to/from a web server. When receiving data from a web server, the data is always a string. Parse the data with JSON.parse(), and the data becomes a JavaScript object.
W3Schools
w3schools.com › js › js_json_stringify.asp
JSON.stringify()
Use the JavaScript function JSON.stringify() to convert it into a string.
ReqBin
reqbin.com › code › javascript › x1ezvres › javascript-object-to-json-example
How do I convert object to JSON in JavaScript?
When converting a JavaScript object to JSON with the JSON.stringify(value, replacer, space) method, you can use the "replacer" function to alter the resulting JSON.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › JSON › parse
JSON.parse() - JavaScript | MDN
The JSON.parse() static method parses a JSON string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Scripting › JSON
Working with JSON - Learn web development | MDN
If you load this JSON in your JavaScript program as a string, you can parse it into a normal object and then access the data inside it using the same dot/bracket notation we looked at in the JavaScript object basics article. For example: ... First, we have the variable name — superHeroes. Inside that, we want to access the members property, so we use .members.
Jsontostring
jsontostring.com
Convert JSON to String Online
Convert JSON to String Online with our tool. Our Javascript Object to String Converter can convert multiline content with full accuracy online.
ReqBin
reqbin.com › code › javascript › wqoreoyp › javascript-json-stringify-example
How to stringify a JavaScript object to JSON string?
The JSON.stringify(value, replacer, space) method converts JavaScript objects to a JSON string. The resulting JSON string is a JSON-formatted or serialized object that can be sent over the network or stored on a disk.