Created
December 25, 2017 19:45
-
-
Save davidicus/dbeae7be949c32237c47ae99c5e60556 to your computer and use it in GitHub Desktop.
Prettify JSON response for console.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify | |
// 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. | |
// @param {object} - The value to convert to a JSON string. | |
// @param {func/ array} - function that alters the behavior of the stringification process, or an array of String and Number objects that serve as a whitelist for selecting/filtering the properties | |
// @return {json} - A JSON string representing the given value. | |
JSON.stringify(<object>, <function/array>, <integer>); | |
// const obj = {Name: "David", Age: 37, Sex: true} | |
// JSON.stringify(obj, null, 2); | |
// JSON.stringify(obj, ["Name"], 2); | |
// prints out | |
"{ | |
"Name": "David", | |
"Age": 37, | |
"Sex": true | |
}" | |
"{ | |
"Name": "David" | |
}" | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment