Error on loadJSON

I’m attempting to save some data but i’m getting the following error:

XML Parsing Error: syntax error
Location: file:///path/JS/Domino/data/test.json
Line Number 1, Column 1:
(there’s nothing after de colon)

I tried to debug this in the firefox console the following way (the variable’s name is pieces)

saveJSON(pieces, ‘save.json’) // correctly prompts save and creates file
// opening the file on firefox reveals that the file was saved as a proper JSON object

loadJSON(‘save.json’) // error happens

I verified that the path is correct and tried saving a JSON.stringify object and using loadStrings but got the same result.

1 Like

just for understanding,
you run p5.js
from
https://editor.p5js.org/ ?
in what browser?
on a win ?10? computer,
and you want load a file what is on that computer?

i hope that is not possible!

you should upload the file like to /data/ or /assets/ for your online account,
or use something like DROP ( a window what expects you upload (drag/drop) a file interactively )

I run an offline project and open the html file in firefox and usually I have no problem.
I am using a 2015 MBP.
I’m saving and loading the data locally.

also the saving by js. to HD is not possible,
what you do is you download it interactively
( means you save it manually to HD, and also you can upload it manually … )
but never should JS read and write automatically from/to your drive

Saving is indeed manual. I have however, seen occasions where the loading of JSON objects is done manually, as long as it is done within the folder where the project is saved. (this example from the coding train: https://www.youtube.com/watch?v=U9wiMM3BqLU&t=687s)

yes, that would be comparable with a uploaded file i mentioned above

  • Does your saved JSON contain accented characters? :thinking:
  • If it is so, you should check whether your “.html” file contains: <meta charset=UTF-8> :smirk:
  • Otherwise, I don’t have any idea why saveJSON() would generate an unparsable file. :dizzy_face:
  • Unless your pieces{} object is somehow using invalid JSON syntax. :hushed:

BtW, I’ve got this online sketch which loads a JSON w/ accented characters in it:

ThimbleProjects.org/gotoloop/91698/
ThimbleProjects.org/gotoloop/91698/RiverNames.js
ThimbleProjects.org/gotoloop/91698/rivers.json

Just numbers… from what i can tell saveJSON() works as it is supposed to (otherwise maybe firefox would not be able to load the project) and it’s loadJSON() the one not working properly

i’ll check it out thank you!

But isn’t saveJSON() the function which created the file which loadJSON() is failing to parse? :grimacing: