# Unable to get data from .JSON files

**URL:** <https://discourse.processing.org/t/unable-to-get-data-from-json-files/9971>\
**Category:** Coding Questions\
**Created:** [April 4, 2019, 7:28pm UTC](https://discourse.processing.org/t/unable-to-get-data-from-json-files/9971 "2019-04-04T19:28:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![peachman](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@peachman](https://discourse.processing.org/u/peachman)\
**Post date:** [April 4, 2019, 7:28pm UTC](https://discourse.processing.org/t/unable-to-get-data-from-json-files/9971/1 "2019-04-04T19:28:41Z")

</div>

Hi All,

I have been able to get data from JSON files before, but i am unable to get data from this one ‘[https://www.osrsbox.com/osrsbox-db/items-json-slot/items-2h.json](https://www.osrsbox.com/osrsbox-db/items-json-slot/items-2h.json)’

```auto
function preload(){
 items = loadJSON('https://www.osrsbox.com/osrsbox-db/items-json-slot/items-2h.json')
  
}

function setup() {
  noCanvas();
  print(items);
  Item = items.839.id
  
  print(Item.length);
  for (var i = 0; i < Item.length; i++){
    print(Item[i]);
    
  }
}

function draw() {

}

```

I am getting Error on Item = items.839.id with this error message ‘Uncaught SyntaxError: Unexpected number (sketch: line 10)’

Is anyone able to help? thanks in advance!

Thanks

Ryan

---

<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:** [April 4, 2019, 7:50pm UTC](https://discourse.processing.org/t/unable-to-get-data-from-json-files/9971/2 "2019-04-04T19:50:31Z")

</div>

```auto

void setup() {

  JSONObject items = loadJSONObject("https://www.osrsbox.com/osrsbox-db/items-json-slot/items-2h.json");

  // println(items); 

  JSONObject Item = items.getJSONObject("839"); 

  println(Item.size());
  println("-----------------------"); 
  for (int i = 0; i < Item.size(); i++) {
    print(Item.get(str(i))+" ");
  }
}

void draw() {
  //
}

```

---

<div class="post-metadata">

**Author:** ![peachman](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@peachman](https://discourse.processing.org/u/peachman)\
**Post date:** [April 4, 2019, 8:14pm UTC](https://discourse.processing.org/t/unable-to-get-data-from-json-files/9971/3 "2019-04-04T20:14:01Z")

</div>

Hi Chrisir, thanks for reply! Is there a way of looping through all the JSON objects in the JSON file?

---

<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:** [April 4, 2019, 8:20pm UTC](https://discourse.processing.org/t/unable-to-get-data-from-json-files/9971/4 "2019-04-04T20:20:23Z")

</div>

they all seem to be null

```auto

void setup() {

  JSONObject items = loadJSONObject("https://www.osrsbox.com/osrsbox-db/items-json-slot/items-2h.json");

  // println(items); 

  for (int i = 0; i < items.size(); i++) {

    JSONObject Item = items.getJSONObject(str(i)); 
    println (i);
    println(Item); 
    println ("------------------------------------------------------------------");
    // print(" "+Item.get(str(0))+" ");
  }

  //println(Item.size());
  //println("-----------------------"); 
  //for (int i = 0; i < Item.size(); i++) {
  // print(Item.get(str(i))+" ");
  //}
}

void draw() {
  //
}

```

---

<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:** [April 4, 2019, 11:13pm UTC](https://discourse.processing.org/t/unable-to-get-data-from-json-files/9971/5 "2019-04-04T23:13:54Z")

</div>

Some online sketch examples on JSON: 🕶

> **[OpenWeatherMapJSON](http://bl.ocks.org/GoSubRoutine/5fbc03e019c53254a2ba7e7fd3318b45)**
>
> GoSubRoutine’s Block 5fbc03e019c53254a2ba7e7fd3318b45

  

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

  

> **[JSON Wikipedia CORS Origin](https://bl.ocks.org/GoSubRoutine/f13a55e7cfaabea6aa6bdf028c1f2f1e)**
>
> GoSubRoutine’s Block f13a55e7cfaabea6aa6bdf028c1f2f1e

---

<div class="post-metadata">

**Author:** ![peachman](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@peachman](https://discourse.processing.org/u/peachman)\
**Post date:** [April 6, 2019, 2:37pm UTC](https://discourse.processing.org/t/unable-to-get-data-from-json-files/9971/6 "2019-04-06T14:37:41Z")

</div>

HI,

I cant seem to get JSONObject to work in the P5 online editor? Am I missing something here?

Thanks

Ryan

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 9, 2019, 6:50am UTC](https://discourse.processing.org/t/unable-to-get-data-from-json-files/9971/7 "2019-04-09T06:50:28Z")

</div>

> [@peachman](#):
>
> Item = items.839.id

First, notice that this there is no such syntax `items.839.id`.

> [@peachman](#):
>
> I cant seem to get JSONObject to work

Second, Chrisir gave you a Processing(Java) solution – for p5.js, JSON is imported directly to native JavaScript objects, which you then access with normal JavaScript notation. Additional reference / examples:

> **[reference | p5.js](https://p5js.org/reference/#/p5/loadJSON)**
>
> p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.

> **[examples | p5.js](https://p5js.org/examples/advanced-data-load-saved-json.html)**
>
> p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.
