# Error on loadJSON

**URL:** <https://discourse.processing.org/t/error-on-loadjson/11439>\
**Category:** Coding Questions\
**Created:** [May 20, 2019, 7:13pm UTC](https://discourse.processing.org/t/error-on-loadjson/11439 "2019-05-20T19:13:34Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![thealex23ro](https://avatars.discourse-cdn.com/v4/letter/t/ecccb3/32.png) [@thealex23ro](https://discourse.processing.org/u/thealex23ro)\
**Post date:** [May 20, 2019, 7:13pm UTC](https://discourse.processing.org/t/error-on-loadjson/11439/1 "2019-05-20T19:13:34Z")

</div>

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.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e57d43bbb4c70ad8a0262b26194241b27204044d.png)

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [May 21, 2019, 1:39am UTC](https://discourse.processing.org/t/error-on-loadjson/11439/2 "2019-05-21T01:39:58Z")

</div>

just for understanding,  
you run p5.js  
from  
[https://editor.p5js.org/](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 )

---

<div class="post-metadata">

**Author:** ![thealex23ro](https://avatars.discourse-cdn.com/v4/letter/t/ecccb3/32.png) [@thealex23ro](https://discourse.processing.org/u/thealex23ro)\
**Post date:** [May 21, 2019, 1:42am UTC](https://discourse.processing.org/t/error-on-loadjson/11439/3 "2019-05-21T01:42:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [May 21, 2019, 1:45am UTC](https://discourse.processing.org/t/error-on-loadjson/11439/4 "2019-05-21T01:45:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thealex23ro](https://avatars.discourse-cdn.com/v4/letter/t/ecccb3/32.png) [@thealex23ro](https://discourse.processing.org/u/thealex23ro)\
**Post date:** [May 21, 2019, 2:06am UTC](https://discourse.processing.org/t/error-on-loadjson/11439/5 "2019-05-21T02:06:27Z")

</div>

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](https://www.youtube.com/watch?v=U9wiMM3BqLU&t=687s))

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [May 21, 2019, 2:14am UTC](https://discourse.processing.org/t/error-on-loadjson/11439/6 "2019-05-21T02:14:08Z")

</div>

> [@thealex23ro](#):
>
> as long as it is done within the folder where the project is saved

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

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 21, 2019, 2:24am UTC](https://discourse.processing.org/t/error-on-loadjson/11439/7 "2019-05-21T02:24:05Z")

</div>

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

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

[ThimbleProjects.org/gotoloop/91698/](http://ThimbleProjects.org/gotoloop/91698/)  
[ThimbleProjects.org/gotoloop/91698/RiverNames.js](http://ThimbleProjects.org/gotoloop/91698/RiverNames.js)  
[ThimbleProjects.org/gotoloop/91698/rivers.json](http://ThimbleProjects.org/gotoloop/91698/rivers.json)

---

<div class="post-metadata">

**Author:** ![thealex23ro](https://avatars.discourse-cdn.com/v4/letter/t/ecccb3/32.png) [@thealex23ro](https://discourse.processing.org/u/thealex23ro)\
**Post date:** [May 21, 2019, 2:27am UTC](https://discourse.processing.org/t/error-on-loadjson/11439/8 "2019-05-21T02:27:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thealex23ro](https://avatars.discourse-cdn.com/v4/letter/t/ecccb3/32.png) [@thealex23ro](https://discourse.processing.org/u/thealex23ro)\
**Post date:** [May 21, 2019, 2:29am UTC](https://discourse.processing.org/t/error-on-loadjson/11439/9 "2019-05-21T02:29:54Z")

</div>

i’ll check it out thank you!

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 21, 2019, 2:33am UTC](https://discourse.processing.org/t/error-on-loadjson/11439/10 "2019-05-21T02:33:23Z")

</div>

> [@thealex23ro](#):
>
> … and it’s **loadJSON()** the one not working properly.

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