Last active
February 24, 2021 11:34
-
-
Save kieranbarker/16b709b4177dfa7b149ef6ab5315a089 to your computer and use it in GitHub Desktop.
Format a JSON string for readability
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
/** | |
* Format a JSON string for readability | |
* @param {String} text The JSON string | |
* @param {Number|String} space The number of spaces, or a string, to indent by | |
* @returns {String} The newly formatted JSON string | |
* @license MIT | |
*/ | |
function formatJSON (text, space = 2) { | |
return JSON.stringify(JSON.parse(text), null, space); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment