This is an example copied from Java Processing tutorials and would like to have something like that in Python Processing.
String[] species = { "Capra hircus", "Panthera pardus", "Equus zebra" };
String[] names = { "Goat", "Leopard", "Zebra" };
JSONArray values;
void setup() {
values = new JSONArray();
for (int i = 0; i < species.length; i++) {
JSONObject animal = new JSONObject();
animal.setInt("id", i);
animal.setString("species", species[i]);
animal.setString("name", names[i]);
values.setJSONObject(i, animal);
}
saveJSONArray(values, "data/new.json");
}
This is what I've already tried in Python.
import json
values = JSONArray
species = [ "Capra hircus", "Panthera pardus", "Equus zebra"]
names = [ "Goat", "Leopard", "Zebra" ]
def setup():
for i in range(len(species)):
animal = JSONObject
animal.setInt("id", i)
animal.setString("species", species[i])
animal.setString("name", names[i])
values.setJSONObject(i, animal)
saveJSONArray(values, "data/new.json")
After running the program I'm getting the following error:
NameError: name 'JSONArray' is not defined
I know there should be another way of declaring JSON object in Python Processing but I am new to Python so I have no idea what the mistake could be.
Thanks in advance :)