p5.js-editor
p5.js-editor copied to clipboard
saveJSON() not working outside setup()
I've modified the example of saveJSON() on the p5.js website to save outside setup().
Running the code in the editor outputs a weird string instead of valid JSON.
var json;
function setup() {
json = {}; // new JSON Object
json.id = 0;
json.species = 'Panthera leo';
json.name = 'Lion';
}
function draw() {
}
function mousePressed() {
saveJSON(json, 'lion.json');
}
Content of lion.json when running the code in the editor:
�w^~)�
Content of lion.json when running the code in the browser:
{
"id": 0,
"species": "Panthera leo",
"name": "Lion"
}