Skip to content

Instantly share code, notes, and snippets.

@stewart
Created February 17, 2014 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stewart/9057871 to your computer and use it in GitHub Desktop.
Save stewart/9057871 to your computer and use it in GitHub Desktop.
Stringify supports pretty-printing
var object = {
vendorId: 6708,
productId: 515,
analogSticks: [
{ name: "left", x: 6, y: 7 },
{ name: "right", x: 8, y: 9 }
],
};
JSON.stringify(object);
//=> {"vendorId":6708,"productId":515,"analogSticks":[{"name":"left","x":6,"y":7},{"name":"right","x":8,"y":9}]}
JSON.stringify(object, null, 2);
// => {
// => "vendorId": 6708,
// => "productId": 515,
// => "analogSticks": [
// => {
// => "name": "left",
// => "x": 6,
// => "y": 7
// => },
// => {
// => "name": "right",
// => "x": 8,
// => "y": 9
// => }
// => ]
// => }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment