jmorrow1 / JSON-for-Processing

Tools to make saving and loading in Processing more convenient.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JSON-Tools-For-Processing

Utilities to make saving and loading in Processing more convenient.

Code Reduction

In Processing, to save an array of floating points, xs, to a JSONObject, json, you would typically write something like:

JSONArray js = new JSONArray();
for (int i=0; i<xs.length; i++) {
    js.setFloat(i, xs[i]);
}
json.setJSONArray("xs", js);

With this library, you can instead write:

json.setJSONArray("xs", Util.jsonify(xs));

To load an array of floating points from a JSONObject, you would typically write something like this:

JSONArray js = json.getJSONArray("xs");
float[] xs = new float[js.size()];
for (int i=0; i<js.size(); i++) {
    xs[i] = js.getFloat(i);
}

With this library, you can instead write:

float[] xs = Util.toFloatArray(json.getJSONArray("xs"));

About

Tools to make saving and loading in Processing more convenient.

License:MIT License


Languages

Language:Java 100.0%