Skip to content

Instantly share code, notes, and snippets.

@yannbertrand
Last active August 29, 2015 14:24
Show Gist options
  • Save yannbertrand/1844f4a95a8d8ddcd12e to your computer and use it in GitHub Desktop.
Save yannbertrand/1844f4a95a8d8ddcd12e to your computer and use it in GitHub Desktop.
JSON.stringify tips
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"
// }
// ]
@yannbertrand
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment