JSON.stringify()
The JSON.stringify() method converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified, or optionally including 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 Optional A function that alters the behavior of the stringification process, or an array of String and Numberobjects that serve as a whitelist for selecting/filtering the properties of the value object to be included in the JSON string. If this value is null or not provided, all properties of the object are included in the resulting JSON string. space Optional A String or Number object that's used to insert white space into the output JSON string for readability purposes. If this is a Number, it indicates the number of space characters to use as white space; this number is capped at 10 (if it is greater, the value is just 10). Values less than 1 indicate that no space should be used. If this is a String, the string (or the first 10 characters of the string, if it's longer than that) is used as white space. If this parameter is not provided (or is null), no white space is used.
Return value
A JSON string representing the given value. Description
JSON.stringify() converts a value to JSON notation representing it: Properties of non-array objects are not guaranteed to be stringified in any particular order. Do not rely on ordering of properties within the same object within the stringification. Boolean, Number, and String objects are converted to the corresponding primitive values during stringification, in accord with the traditional conversion semantics. If undefined, a function, or a symbol is encountered during conversion it is either omitted (when it is found in an object) or censored to null (when it is found in an array). JSON.stringify can also just return undefined when passing in "pure" values like JSON.stringify(function(){})or JSON.stringify(undefined). All symbol-keyed properties will be completely ignored, even when using the replacer function. Non-enumerable properties will be ignored
JSON.stringify({}); // '{}'JSON.stringify(true); // 'true'JSON.stringify('foo'); // '"foo"'JSON.stringify([1, 'false', false]); // '[1,"false",false]'JSON.stringify({ x: 5 }); // '{"x":5}'JSON.stringify(new Date(2006, 0, 2, 15, 4, 5)) // '"2006-01-02T15:04:05.000Z"'JSON.stringify({ x: 5, y: 6 });// '{"x":5,"y":6}' or '{"y":6,"x":5}'JSON.stringify([new Number(1), new String('false'), new Boolean(false)]);// '[1,"false",false]'JSON.stringify({ x: [10, undefined, function(){}, Symbol('')] }); // '{"x":[10,null,null,null]}' // Symbols:JSON.stringify({ x: undefined, y: Object, z: Symbol('') });// '{}'JSON.stringify({ [Symbol('foo')]: 'foo' }