Stringify - Convert JSON to string
Other topicsConvert simple JSON object to simple string
var JSONObject = {
stringProp: 'stringProp',
booleanProp: false,
intProp: 8
}
var JSONString = JSON.stringify(JSONObject);
console.log(JSONString);
/* output
* {"stringProp":"stringProp","booleanProp":false,"intProp":8}
*/
Stringify with filter
var JSONObject = {
stringProp: 'stringProp',
booleanProp: false,
intProp: 8
}
var JSONString = JSON.stringify(JSONObject, ['intProp']);
console.log(JSONString);
/* output
* {"intProp":8}
*/
Stringify with white-space
var JSONObject = {
stringProp: 'stringProp',
booleanProp: false,
intProp: 8
}
var JSONString = JSON.stringify(JSONObject, null, 2);
console.log(JSONString);
/* output:
* {
* "stringProp": "stringProp",
* "booleanProp": false,
* "intProp": 8
* }
*/
Parameters:
Param | Details |
---|
Object | (Object) The JSON object |
Replacer | (Function | Array<string | number> - optiotinal) filter Function | Array |
Space | (Number | string - optional) Amount of white space in the JSON |
Contributors
Topic Id: 7824
Example Ids: 25474,25475,25476
This site is not affiliated with any of the contributors.