Hello @dneilan,
This is an interesting topic and I am interested in your manual conversion.
A simple example will suffice.
This was a very quick effort for me and the data was straightforward from one of the Processing examples:
// Reference:
// https://www.freecodecamp.org/news/jsonobject-tostring-how-to-convert-json-to-a-string-in-java/
String[] species = { "Capra hircus", "Panthera pardus", "Equus zebra" };
String[] names = { "Goat", "Leopard", "Zebra" };
JSONArray values;
String [] JSONtoArr;
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);
}
String s = values.toString();
println(s);
println();
JSONtoArr = split(s, '\n');
printArray(JSONtoArr );
println();
for(int i=0; i< JSONtoArr.length; i++)
{
JSONtoArr[i] = JSONtoArr[i].trim();
JSONtoArr[i] = JSONtoArr[i].replaceAll("\"", "");
}
printArray(JSONtoArr);
println();
saveStrings("test.txt", JSONtoArr);
}
I always enjoy the challenge of custom parsing data to access elements and wield them with code.
Have fun!
:)
