-
-
Save Uvacoder/1e2e77586a00c8bcbcb1fd1ecadb29b1 to your computer and use it in GitHub Desktop.
Stringify object with no quotes. https://jsfiddle.net/DerekL/mssybp3k/
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
| function stringify(obj_from_json){ | |
| if(typeof obj_from_json !== "object" || Array.isArray(obj_from_json)){ | |
| // not an object, stringify using native function | |
| return JSON.stringify(obj_from_json); | |
| } | |
| // Implements recursive object serialization according to JSON spec | |
| // but without quotes around the keys. | |
| let props = Object | |
| .keys(obj_from_json) | |
| .map(key => `${key}:${stringify(obj_from_json[key])}`) | |
| .join(","); | |
| return `{${props}}`; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment