Last active
August 29, 2015 14:24
-
-
Save yannbertrand/1844f4a95a8d8ddcd12e to your computer and use it in GitHub Desktop.
JSON.stringify tips
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
| var toto = { | |
| foundation: 'Mozilla', | |
| model: 'box', | |
| week: 45, | |
| transport: 'bus', | |
| month: 7 | |
| }; | |
| JSON.stringify(toto); | |
| // '{"foundation":"Mozilla","model":"box","week":45,"transport":"bus","month":7}' | |
| JSON.stringify(toto, ['week', 'month']); | |
| // '{"week":45,"month":7}' | |
| JSON.stringify(toto, null, ' '); | |
| // '{ | |
| // "foundation": "Mozilla", | |
| // "model": "box", | |
| // "week": 45, | |
| // "transport": "bus", | |
| // "month": 7 | |
| // }' | |
| toto = [ | |
| { | |
| foundation: 'Mozilla', | |
| model: 'box', | |
| week: 45, | |
| transport: 'bus', | |
| month: 7 | |
| }, | |
| { | |
| foundation: 'Google', | |
| model: 'box', | |
| week: 22, | |
| transport: 'car', | |
| month: 3 | |
| } | |
| ]; | |
| JSON.stringify(toto, ['foundation'], ' '); | |
| // [ | |
| // { | |
| // "foundation": "Mozilla" | |
| // }, | |
| // { | |
| // "foundation": "Google" | |
| // } | |
| // ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify for more informations