# Newbie question: can't load JSON with url

**URL:** <https://discourse.processing.org/t/newbie-question-cant-load-json-with-url/5665>\
**Category:** Coding Questions\
**Created:** [November 18, 2018, 10:41am UTC](https://discourse.processing.org/t/newbie-question-cant-load-json-with-url/5665 "2018-11-18T10:41:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivano](https://avatars.discourse-cdn.com/v4/letter/i/edb3f5/32.png) [@Ivano](https://discourse.processing.org/u/Ivano)\
**Post date:** [November 18, 2018, 10:41am UTC](https://discourse.processing.org/t/newbie-question-cant-load-json-with-url/5665/1 "2018-11-18T10:41:57Z")

</div>

Hi

I manage to solve all of the problems i encountered on my own, by reading reference page, googling, by watching yt tutorials… but i have problem with loading JSON with url which is not working even thought I done everything by the book…

Here is the code, the simplest possible - and it’s not working:

```auto
function setup() {
 var url = 'http://api.open-notify.org/iss-now.json';
 loadJSON(url, gotData, 'jsonp');
}

function gotData (data) {
print (data.iss_position.latitude);
}

```

It’s not working with or without “jsonp” argument.

If i put the json content in local file called iss.json, than it’s working.

```auto
function setup() {
  // createCanvas (600,400);
 var url = 'iss.json';
 loadJSON(url, gotData);
}

function gotData (data) {
print (data.iss_position.latitude);
}

```

The same is with open weather API, it’s not retrieving the data.

But [earthquake.usgs.gov](http://earthquake.usgs.gov) from reference loadJSON example is working just fine…

Ty for any information.  
Best regards

---

<div class="post-metadata">

**Author:** ![Sarah](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sarah/32/1675_2.png) [@Sarah](https://discourse.processing.org/u/Sarah)\
**Post date:** [November 18, 2018, 12:17pm UTC](https://discourse.processing.org/t/newbie-question-cant-load-json-with-url/5665/2 "2018-11-18T12:17:05Z")

</div>

The code you put is working for me, it might be a network issue. Try going to [http://api.open-notify.org/iss-now.json](http://api.open-notify.org/iss-now.json) in your browser, does it load?

---

<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:** [November 18, 2018, 12:37pm UTC](https://discourse.processing.org/t/newbie-question-cant-load-json-with-url/5665/3 "2018-11-18T12:37:24Z")

</div>

sorry, i play also first time with this,  
and i use win7, processing 3.4 mode Java

```auto
JSONObject json,jposition;
String url = "http://api.open-notify.org/iss-now.json";
int cols;
float lat,lng;

void setup() {
  json = loadJSONObject(url);
  cols = json.size();
  println("cols: "+cols);  
  println(json);
  jposition = json.getJSONObject("iss_position");
  println(jposition);
  lat = jposition.getFloat("latitude");
  lng = jposition.getFloat("longitude");
  println("lat: "+lat+" lng: "+lng);
  //println("https://www.google.com/maps/@"+lat+","+lng+",3z");
  println("https://www.google.com/maps/@"+lat+","+lng+",3224132m/data=!3m1!1e3");

}

```

but using the CALLBACK ? 'jsonp"  
i read the url is

> [http://api.open-notify.org/iss-now.json?callback=CALLBACK](http://api.open-notify.org/iss-now.json?callback=CALLBACK)

and the result is

```auto
CALLBACK({"timestamp": 1542545841, "iss_position": {"latitude": "-37.2571", "longitude": "40.6357"}, "message": "success"})

```

---

<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:** [November 18, 2018, 1:03pm UTC](https://discourse.processing.org/t/newbie-question-cant-load-json-with-url/5665/4 "2018-11-18T13:03:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ivano](https://avatars.discourse-cdn.com/v4/letter/i/edb3f5/32.png) [@Ivano](https://discourse.processing.org/u/Ivano)\
**Post date:** [November 18, 2018, 4:01pm UTC](https://discourse.processing.org/t/newbie-question-cant-load-json-with-url/5665/5 "2018-11-18T16:01:19Z")

</div>

Hi! I can open the json in browser without a problem. I now figured out use of console (i use p5.js web editor)… so i find out that i am getting errors:

```auto
Mixed Content: The page at 'https://editor.p5js.org/Ivanko/sketches/rJ7nG9R6X' was loaded over HTTPS, but requested an insecure resource 'http://api.open-notify.org/iss-now.json'. This request has been blocked; the content must be served over HTTPS.
VM111 about:srcdoc:1 Uncaught (in promise) TypeError: Failed to fetch
VM111 about:srcdoc:1 Uncaught (in promise) TypeError: Failed to fetch

```

Regarding the first error, if i put [https://api.open-notify.org/iss-now.json](https://api.open-notify.org/iss-now.json) in browser, with https not with http, i get blank page, so i must use http in url, but why am i getting that error then.

And for the second… well, googling doesn’t really help with my limited knowledge

---

<div class="post-metadata">

**Author:** ![Sarah](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sarah/32/1675_2.png) [@Sarah](https://discourse.processing.org/u/Sarah)\
**Post date:** [November 18, 2018, 10:27pm UTC](https://discourse.processing.org/t/newbie-question-cant-load-json-with-url/5665/6 "2018-11-18T22:27:02Z")

</div>

I think it can’t be reached because [http://api.open-notify.org/iss-now.json](http://api.open-notify.org/iss-now.json) is not secure, so the p5.js online editor won’t allow it.

If you use a normal p5.js sketch, or in the p5.js online editor go to _File \> Download_, then click on index.html, does it work?

---

<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:** [November 19, 2018, 1:15am UTC](https://discourse.processing.org/t/newbie-question-cant-load-json-with-url/5665/7 "2018-11-19T01:15:35Z")

</div>

in processing 3.4 mode p5.js  
( system: win7 browser: firefox 63 )

```auto
var data, lat, lng, googlemap="";

function setup() {
  createCanvas (500, 500);
  var url = 'http://api.open-notify.org/iss-now.json';
  loadJSON(url,gotData);
}

function draw() {
  background(200,200,0);
  stroke(0);fill(0);
  text(" lat " + lat + " lng " + lng,20,20);
  text(googlemap,20,40);
}

function gotData (data) {
  //print (data);
  lat = data.iss_position.latitude;
  lng = data.iss_position.longitude;
  googlemap = "https://www.google.com/maps/@"+nf(lat,1,7)+","+nf(lng,1,7)+",3224132m/data=!3m1!1e3";
  print(googlemap);
}

```

works, so it is definitely a “p5.js online editor” problem  
but i do not know how to produce a link on the canvas

---

<div class="post-metadata">

**Author:** ![Ivano](https://avatars.discourse-cdn.com/v4/letter/i/edb3f5/32.png) [@Ivano](https://discourse.processing.org/u/Ivano)\
**Post date:** [November 19, 2018, 8:30am UTC](https://discourse.processing.org/t/newbie-question-cant-load-json-with-url/5665/8 "2018-11-19T08:30:14Z")

</div>

Yeah. It works when downloaded.  
I will also use processing desktop app with p5.js mode in combination with web editor in the future.

Thanks!
