# loadJSON() function error message

**URL:** <https://discourse.processing.org/t/loadjson-function-error-message/27893>\
**Category:** Coding Questions\
**Created:** [February 17, 2021, 8:08pm UTC](https://discourse.processing.org/t/loadjson-function-error-message/27893 "2021-02-17T20:08:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![EunieceHarris](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EunieceHarris](https://discourse.processing.org/u/EunieceHarris)\
**Post date:** [February 17, 2021, 8:08pm UTC](https://discourse.processing.org/t/loadjson-function-error-message/27893/1 "2021-02-17T20:08:22Z")

</div>

I’m a newbie to p5.js but I’ve been playing around with using API’s. Whenever I call an API using the function loadJSON(), no matter what I always get the same error message that reads:

_p5.js says: It looks like there was a problem loading your JSON file. Try checking if the file path ([https://api.open-notify.org/astros.json](https://api.open-notify.org/astros.json)) is correct, hosting the file online, or running a local server. (More info at [Local server · processing/p5.js Wiki · GitHub](https://github.com/processing/p5.js/wiki/Local-server))_

I made sure to type the URL for the API with my key but it never works, even for an API that doesn’t require a key. So something like this:

```auto
function setup() {
  // createCanvas(400, 400);
  loadJSON("https://api.open-notify.org/astros.json", gotData, 'jsonp');
}

function gotData(data) {
  console.log(data);
}

function draw() {
  //background(220);
}

```

Doesn’t print, or in this case logs the array. Any ideas??

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 17, 2021, 9:29pm UTC](https://discourse.processing.org/t/loadjson-function-error-message/27893/2 "2021-02-17T21:29:07Z")

</div>

Did you try [http://api.open-notify.org/astros.json](http://api.open-notify.org/astros.json)

without the s ?

---

<div class="post-metadata">

**Author:** ![EunieceHarris](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EunieceHarris](https://discourse.processing.org/u/EunieceHarris)\
**Post date:** [February 17, 2021, 9:30pm UTC](https://discourse.processing.org/t/loadjson-function-error-message/27893/3 "2021-02-17T21:30:12Z")

</div>

Yep. I figured adding it would help but it didn’t. 😢

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 17, 2021, 10:56pm UTC](https://discourse.processing.org/t/loadjson-function-error-message/27893/4 "2021-02-17T22:56:51Z")

</div>

Is this solved? I loaded it without the s

---

<div class="post-metadata">

**Author:** ![EunieceHarris](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EunieceHarris](https://discourse.processing.org/u/EunieceHarris)\
**Post date:** [February 17, 2021, 10:59pm UTC](https://discourse.processing.org/t/loadjson-function-error-message/27893/5 "2021-02-17T22:59:30Z")

</div>

![Screen Shot 2021-02-17 at 17.59.07](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/c0b87756f7fb589f151c92a41278f0594d347bd1.png)  
Still nothing, unfortunately.

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [February 18, 2021, 12:22am UTC](https://discourse.processing.org/t/loadjson-function-error-message/27893/6 "2021-02-18T00:22:12Z")

</div>

Hi,

**I tested this on the p5 web editor.**

If you look at the console output by pressing `F12`, this is the error message on Firefox :

[https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSDidNotSucceed](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSDidNotSucceed)

What is strange is that they say that it is not related to CORS policy and it works when putting the single link in a new browser tab…

I also tested this on a separate html file :

```auto
const request = new XMLHttpRequest();

request.open('GET', "http://api.open-notify.org/astros.json");
request.responseType = 'json';
request.send();

request.onload = function() {
  console.log(request.response);
}

```

> Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at [https://api.open-notify.org/astros.json](https://api.open-notify.org/astros.json). (Reason: CORS request did not succeed).

I don’t understand why some public API doesn’t support CORS because otherwise no one can make request to their API from a browser…

It doesn’t work so I would contact the author of the API 😉

Another link that can help you to understand the issue :

[https://github.com/processing/p5.js/issues/1451](https://github.com/processing/p5.js/issues/1451)

---

<div class="post-metadata">

**Author:** ![EunieceHarris](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EunieceHarris](https://discourse.processing.org/u/EunieceHarris)\
**Post date:** [February 18, 2021, 12:27am UTC](https://discourse.processing.org/t/loadjson-function-error-message/27893/7 "2021-02-18T00:27:55Z")

</div>

This is something different but what is the explanation of the following code not looping through an array of a JSON file:

[https://editor.p5js.org/eunieceharris/sketches/c0B0iuO9k](https://editor.p5js.org/eunieceharris/sketches/c0B0iuO9k)

---

<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:** [February 19, 2021, 7:33am UTC](https://discourse.processing.org/t/loadjson-function-error-message/27893/8 "2021-02-19T07:33:38Z")

</div>

> **[JSON Open-Notify ISS](http://Bl.ocks.org/GoSubRoutine/7a567f0510b338b6d0fc1ef53f24f10e)**
>
> GoSubRoutine’s Block 7a567f0510b338b6d0fc1ef53f24f10e

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 19, 2021, 10:09am UTC](https://discourse.processing.org/t/loadjson-function-error-message/27893/9 "2021-02-19T10:09:00Z")

</div>

> [@EunieceHarris](#):
>
> what is the explanation of the following code not looping through an array of a JSON file:

Sorry, I don’t know about p5.js but this **processing** code (JAVA flavor) works:

```auto
JSONArray citiesJSONArray; 
String stringCityName;

void setup() {
  size(400, 400);
  citiesJSONArray = loadJSONArray("c1.json");

  for (int x = 0; x < citiesJSONArray.size(); x++) {

    JSONObject oneCityJSONObject = citiesJSONArray.getJSONObject(x); 

    stringCityName = oneCityJSONObject.getString("city");
    println(stringCityName) ;
    // createP(se);
  }
}

void draw() {
  background(120);
  text ("See Direct Window", 44, 44);
}
//

```

Chrisir
