processing / p5.js-editor

Deprecated desktop editor for p5.js
https://p5js.org
MIT License
338 stars 91 forks source link

saveJSON() not working outside setup() #236

Open jvolker opened 8 years ago

jvolker commented 8 years ago

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"
}