Skip to content

Latest commit

 

History

History
53 lines (40 loc) · 1.18 KB

saveData.md

File metadata and controls

53 lines (40 loc) · 1.18 KB

Back to reference

saveData(data, filename = 'export.json', pretty = true)

Saves the given data as a json file to the downlaods folder of the browser. The default file name is export.json but you can give another name as the second argument. pretty set to false will save a file without line breaks which makes it a bit smaller but also less legible.

Example:

If this is your data:

let superheroes = [
  {Name: "Superboy", Height: 170, Weight: 68},
  {Name: "Supergirl", Height: 165, Weight: 54},
  {Name: "Superman", Height: 191, Weight: 101}
]
Example 1:
gmynd.saveData(superheroes);

... gives you this result in the file export.json:

[{
  "Name":"Superboy",
  "Height":170,
  "Weight":68
},{
  "Name":"Supergirl",
  "Height":165,
  "Weight":54
},{
  "Name":"Superman",
  "Height":191,
  "Weight":101
}]
Example 2:
gmynd.saveData(superheroes, 'heroes.json', false)

... gives you this result in the file heroes.json:

[{"Name":"Superboy","Height":170,"Weight":68},{"Name":"Supergirl","Height":165,"Weight":54},{"Name":"Superman","Height":191,"Weight":101}]