# Unable to get JSON file to work in p5.js

**URL:** <https://discourse.processing.org/t/unable-to-get-json-file-to-work-in-p5-js/24116>\
**Category:** Beginners\
**Created:** [September 25, 2020, 12:21pm UTC](https://discourse.processing.org/t/unable-to-get-json-file-to-work-in-p5-js/24116 "2020-09-25T12:21:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam101](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@sam101](https://discourse.processing.org/u/sam101)\
**Post date:** [September 25, 2020, 12:21pm UTC](https://discourse.processing.org/t/unable-to-get-json-file-to-work-in-p5-js/24116/1 "2020-09-25T12:21:50Z")

</div>

I’m trying to load my p5.js sketch, but the sketch keeps coming up as loading. Then when I check to see, there is an error message saying"Uncaught (in promise) SyntaxError: Unexpected token / in JSON at position 0", which I not sure what to do about?

Not sure what to do! Some help will be much appreciated 🙂

---

<div class="post-metadata">

**Author:** ![Sven](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sven/32/8293_2.png) [@Sven](https://discourse.processing.org/u/Sven)\
**Post date:** [September 25, 2020, 7:42pm UTC](https://discourse.processing.org/t/unable-to-get-json-file-to-work-in-p5-js/24116/2 "2020-09-25T19:42:48Z")

</div>

Hello, and welcome to the community! 🥳

I would love to assist you in the debugging effort, but it’s hard without any code to debug. 😉 The only thing I can tell you is what the error message already says; somewhere in the code, a file is loaded and parsed as JSON, but it isn’t JSON (or it’s invalid JSON).

So you either have to change the file’s content to be valid JSON or stop loading the file at all.

---

<div class="post-metadata">

**Author:** ![sam101](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@sam101](https://discourse.processing.org/u/sam101)\
**Post date:** [September 26, 2020, 2:29am UTC](https://discourse.processing.org/t/unable-to-get-json-file-to-work-in-p5-js/24116/3 "2020-09-26T02:29:56Z")

</div>

Okay Thanks for the reply I will give that a go!

---

<div class="post-metadata">

**Author:** ![sam101](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@sam101](https://discourse.processing.org/u/sam101)\
**Post date:** [September 26, 2020, 4:22am UTC](https://discourse.processing.org/t/unable-to-get-json-file-to-work-in-p5-js/24116/4 "2020-09-26T04:22:23Z")

</div>

Hmmm okay, I’ve looked my code again and I still couldn’t find the error. I’ve also check my html as well to see if there was an issue… still not sure…

this is the code so far…

```auto
var data; 
var instagram, snapchat, messenger, facebook, email, instagramCol, snapchatCol, messengerCol, facebookCol, emailCol; 
var sizeMultiplier = 20; 

function preload (){
  data =loadJSON ("Sunday.json");
}
function setup() {
   createCanvas (windowWidth, windowHeight);
   background (255);
   noStroke ();
   textSize (20);
   instagramCol = color (142, 68, 173);
   messengerCol = color (133, 193, 233);
   snapchatCol = color (247, 220, 111);
   facebookCol = color (118, 215, 196);
   emailCol = color (178, 186, 187); 

}

 
function draw () {
  //12:00 am data
  fill (instagramCol);
size = data[8][0]*sizeMultiplier; 
ellipse (20, 40, size, size);

}

```

![Screen Shot 2020-09-26 at 2.21.31 pm](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/599516799bd0e2f07049ddaf97ed7e7609d294f1.png)

If anyone can see what I’ve done wrong that would be great!

---

<div class="post-metadata">

**Author:** ![tony](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tony/32/949_2.png) [@tony](https://discourse.processing.org/u/tony)\
**Post date:** [September 26, 2020, 4:55am UTC](https://discourse.processing.org/t/unable-to-get-json-file-to-work-in-p5-js/24116/5 "2020-09-26T04:55:31Z")

</div>

I’ve had parsing problems in the past due to clumsy, hand written JSON files.

Can you give us more details on `Sunday.json`?

---

<div class="post-metadata">

**Author:** ![sam101](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@sam101](https://discourse.processing.org/u/sam101)\
**Post date:** [September 26, 2020, 5:19am UTC](https://discourse.processing.org/t/unable-to-get-json-file-to-work-in-p5-js/24116/6 "2020-09-26T05:19:04Z")

</div>

so this is the shortened data format for my json data, but the rest follows the same pattern.

```auto
//Notifications received on the 16/08/20
 [
    {
          "12:00 am": {
        "instagram": 0,
        "messenger": 0,
        "snapchat": 0,
        "email": 0,
        "facebook": 0,
        "totalNotification": 0
          }
    },

    {
         "1:00 am": {
        "instagram": 1,
        "messenger": 2,
        "snapchat": 0,
        "email": 0,
        "facebook": 0,
        "totalNotification": 3
         }
    },
    
    
    {
         "2:00 am": {
        "instagram": 0,
        "messenger": 0,
        "snapchat": 0,
        "email": 0,
        "facebook": 0,
        "totalNotification": 0
         }
    },
    
    {
         "3:00 am": {
        "instagram": 0,
        "messenger": 0,
        "snapchat": 0,
        "email": 0,
        "facebook": 0,
        "totalNotification": 0
         }
    },
    
    {
         "4:00 am": {
        "instagram": 0,
        "messenger": 0,
        "snapchat": 0,
        "email": 0,
        "facebook": 0,
        "totalNotification": 0
         }
    },
    
    {
         "5:00 am": {
        "instagram": 0,
        "messenger": 0,
        "snapchat": 0,
        "email": 0,
        "facebook": 0,
        "totalNotification": 0
         }
    },
    
    {
         "6:00 am": {
        "instagram": 0,
        "messenger": 0,
        "snapchat": 0,
        "email": 0,
        "facebook": 0,
        "totalNotification": 0
         }
    }
]

```

---

<div class="post-metadata">

**Author:** ![Sven](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sven/32/8293_2.png) [@Sven](https://discourse.processing.org/u/Sven)\
**Post date:** [September 26, 2020, 7:25am UTC](https://discourse.processing.org/t/unable-to-get-json-file-to-work-in-p5-js/24116/7 "2020-09-26T07:25:53Z")

</div>

> [@sam101](#):
>
> //Notifications received on the 16/08/20

There’s the culprit. 😊 JSON does not support comments, so when the program encounters `/`, it panics and throws the exception `Unexpected token / in JSON at position 0`.

---

<div class="post-metadata">

**Author:** ![sam101](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@sam101](https://discourse.processing.org/u/sam101)\
**Post date:** [September 26, 2020, 7:28am UTC](https://discourse.processing.org/t/unable-to-get-json-file-to-work-in-p5-js/24116/8 "2020-09-26T07:28:11Z")

</div>

aahhh OMG! thanks! That seems to have solved it!
