# Problem with loadJSONArray example

**URL:** <https://discourse.processing.org/t/problem-with-loadjsonarray-example/10207>\
**Category:** Coding Questions\
**Created:** [April 12, 2019, 4:28am UTC](https://discourse.processing.org/t/problem-with-loadjsonarray-example/10207 "2019-04-12T04:28:32Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![wprisk](https://avatars.discourse-cdn.com/v4/letter/w/f08c70/32.png) [@wprisk](https://discourse.processing.org/u/wprisk)\
**Post date:** [April 12, 2019, 4:28am UTC](https://discourse.processing.org/t/problem-with-loadjsonarray-example/10207/1 "2019-04-12T04:28:32Z")

</div>

Hello,

I am trying to run the simple example for “loadJSONArray” found here:  
[https://processing.org/reference/loadJSONArray\_.html](https://processing.org/reference/loadJSONArray_.html)

When I do so (by copying and pasting into a Processing sketch, and also creating the data.json file specified in the comments), I get the error:  
“cannot convert from processing.data.JSONArray to JSONArray”

What is causing this and how can I fix it?

Many thanks in advance,  
Bill

---

<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:** [April 12, 2019, 6:24am UTC](https://discourse.processing.org/t/problem-with-loadjsonarray-example/10207/2 "2019-04-12T06:24:53Z")

</div>

i also just try here  
( win 7 / 64bit / processing 3.5.3 / java mode )  
and it works.  
-a- the file should be at subdir

> data/data.json

and it should look like

```auto
  [
    {
      "id": 0,
      "species": "Capra hircus",
      "name": "Goat"
    },
    {
      "id": 1,
      "species": "Panthera pardus",
      "name": "Leopard"
    },
    {
      "id": 2,
      "species": "Equus zebra",
      "name": "Zebra"
    }
  ]

```

means all that // must be deleted  
the example documentation should  
use

```auto
/*
code
*/

```

instead

```auto
// code

```

what is difficult to copy!  
[reference example use // data, bad for copy · Issue #748 · processing/processing-docs · GitHub](https://github.com/processing/processing-docs/issues/748) (reported)

* * *

a general remark;  
the

```auto
loadXXX(file);

```

uses a friendly trick looking up the file at

> data/file

as soon you once use

```auto
loadXXX(file);
saveXXX(file);

```

you learn that the trick works for load but not for save!  
so please:  
whenever use a filename make it incl path

```auto
String filename = "data/file.ext"

```

and you can do load and save without thinking

---

<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 12, 2019, 8:56am UTC](https://discourse.processing.org/t/problem-with-loadjsonarray-example/10207/3 "2019-04-12T08:56:12Z")

</div>

Are you in Java mode? You should…

---

<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 12, 2019, 12:56pm UTC](https://discourse.processing.org/t/problem-with-loadjsonarray-example/10207/4 "2019-04-12T12:56:05Z")

</div>

I didn’t have any issues running this

@kll remove all // in a section: select with mouse, Menu Edit | Comment/Uncomment…

Chrisir

```auto
JSONArray values;

void setup() {
  size(400, 400); 

  values = loadJSONArray("data.json");

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

    JSONObject animal = values.getJSONObject(i); 

    int id = animal.getInt("id");
    String species = animal.getString("species");
    String name = animal.getString("name");

    println(id + ", " + species + ", " + name);
  }
}
//

```

---

<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:** [April 12, 2019, 1:45pm UTC](https://discourse.processing.org/t/problem-with-loadjsonarray-example/10207/5 "2019-04-12T13:45:21Z")

</div>

> [@Chrisir](#):
>
> I didn’t have any issues running this

pls read my above post again, where i say

> [@kll](#):
>
> and it works.

> [@Chrisir](#):
>
> @kll remove all // in a section: select with mouse, Menu Edit | Comment/Uncomment…

please detail how you make the file, possibly we not know some tricks about the  
processing 3.5.3 IDE / editor

---

<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 12, 2019, 1:49pm UTC](https://discourse.processing.org/t/problem-with-loadjsonarray-example/10207/6 "2019-04-12T13:49:44Z")

</div>

I know, you got it working and I just agreed.

I am referring to:

> please detail how you make the file, possibly we not know some tricks about the  
> processing 3.5.3 IDE / editor

and to:

> means all that // must be deleted  
> the example documentation should  
> use
> 
> ```auto
> /*
> code
> */
> 
> ```

maybe I got you wrong

found here:  
[https://processing.org/reference/loadJSONArray\_.html](https://processing.org/reference/loadJSONArray_.html)

paste into processing

```auto
// [
// {
// "id": 0,
// "species": "Capra hircus",
// "name": "Goat"
// },
// {
// "id": 1,
// "species": "Panthera pardus",
// "name": "Leopard"
// },
// {
// "id": 2,
// "species": "Equus zebra",
// "name": "Zebra"
// }
// ]

```

remove all // in a section: select with mouse, Menu Edit | use **Comment/Uncomment…**

Chrisir

---

<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:** [April 12, 2019, 1:54pm UTC](https://discourse.processing.org/t/problem-with-loadjsonarray-example/10207/7 "2019-04-12T13:54:11Z")

</div>

> [@Chrisir](#):
>
> remove all //

we know that, and the main thing what i pointed out was that that remove is necessary  
for reading the file.

still, you

- copy paste the whole section from reference to your sketch
- you uncomment the data part
- AND THEN?

how you make that section to a file with the IDE editor, please details as i never do this?  
always use my filemanager / make the data subdir / and use external editor,  
COPY PASTE

---

<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 12, 2019, 1:57pm UTC](https://discourse.processing.org/t/problem-with-loadjsonarray-example/10207/8 "2019-04-12T13:57:30Z")

</div>

I do it the same way 😉

---

<div class="post-metadata">

**Author:** ![wprisk](https://avatars.discourse-cdn.com/v4/letter/w/f08c70/32.png) [@wprisk](https://discourse.processing.org/u/wprisk)\
**Post date:** [April 12, 2019, 4:42pm UTC](https://discourse.processing.org/t/problem-with-loadjsonarray-example/10207/9 "2019-04-12T16:42:55Z")

</div>

I am using Processing 3.5.3 and using the IDE on a Mac. I am using Java mode.

The code I have in the sketch is:

```auto
JSONArray values;

void setup() {

  values = loadJSONArray("data.json");

  for (int i = 0; i < values.size(); i++) {
    
    JSONObject animal = values.getJSONObject(i); 

    int id = animal.getInt("id");
    String species = animal.getString("species");
    String name = animal.getString("name");

    println(id + ", " + species + ", " + name);
  }
}

```

In the data folder I have a file “data.json” that contains:

```auto
[
   {
     "id": 0,
     "species": "Capra hircus",
     "name": "Goat"
   },
   {
     "id": 1,
     "species": "Panthera pardus",
     "name": "Leopard"
   },
   {
     "id": 2,
     "species": "Equus zebra",
     "name": "Zebra"
   }
 ]

```

On the Mac, the produces the error cited in my original post:  
“cannot convert from processing.data.JSONArray to JSONArray”

However, I tried this on a Windows machine and it ran fine.

---

<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:** [April 13, 2019, 3:25am UTC](https://discourse.processing.org/t/problem-with-loadjsonarray-example/10207/10 "2019-04-13T03:25:14Z")

</div>

sorry can not help about MAC,  
just hope someone with that hardware can jump in,

but you should be much more detailed about  
hardware and OS revision …  
add can you prepare and run

```auto
void mysysinfo() {
  println( "System : " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch") );
  println( "JAVA : " + System.getProperty("java.home") + " rev: " +javaVersionName);
  println( "user.home : " + System.getProperty("user.home") );
  println( "user.dir : " + System.getProperty("user.dir") );
  println( "sketchPath : " + sketchPath() );
  println( "dataPath : " + dataPath("") );
  println( "dataFile : " + dataFile("") );
}

void setup() {
  mysysinfo();
}

```

and instead of try to build up from “reference”  
just run directly from examples, is faster, less error prone  
from example test:  
… processing-3.5.3\modes\java\examples\Topics\Advanced Data\LoadSaveJSON  
in case its a " build for MAC " problem there could be much more problems.

---

<div class="post-metadata">

**Author:** ![wprisk](https://avatars.discourse-cdn.com/v4/letter/w/f08c70/32.png) [@wprisk](https://discourse.processing.org/u/wprisk)\
**Post date:** [April 14, 2019, 7:54pm UTC](https://discourse.processing.org/t/problem-with-loadjsonarray-example/10207/11 "2019-04-14T19:54:20Z")

</div>

I am able to run the “LoadSaveJSON” example you cite, but it does not involve the “loadJSONArray” method that is provoking the error…

---

<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 14, 2019, 7:57pm UTC](https://discourse.processing.org/t/problem-with-loadjsonarray-example/10207/12 "2019-04-14T19:57:22Z")

</div>

Did you try

processing.data.JSONArray instead of JSONArray

as the error message suggests?

Chrisir

---

<div class="post-metadata">

**Author:** ![wprisk](https://avatars.discourse-cdn.com/v4/letter/w/f08c70/32.png) [@wprisk](https://discourse.processing.org/u/wprisk)\
**Post date:** [April 14, 2019, 8:44pm UTC](https://discourse.processing.org/t/problem-with-loadjsonarray-example/10207/13 "2019-04-14T20:44:40Z")

</div>

How would that be done?

---

<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 18, 2019, 12:05am UTC](https://discourse.processing.org/t/problem-with-loadjsonarray-example/10207/14 "2019-04-18T00:05:29Z")

</div>

> [@wprisk](#):
>
> cannot convert from processing.data.JSONArray to JSONArray

Hmm… Any chance you have another library loaded that defines a JSONArray object? Imported, installed through contributions manager, or in a local jar?

What version of PDE are you running on mac, and what are the installed libraries?
