- Processing
- p5.js
- Processing.py
- Processing for Android
- Processing for Pi

- Processing Foundation

This reference is for Processing 3.0+. If you have a previous version, use the reference included with your software in the Help menu. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.

Name | ### parseJSONArray()
Examples |
    String data = "[ \"Capra hircus\", \"Panthera pardus\", \"Equus zebra\" ]";

    void setup() {
      JSONArray json = parseJSONArray(data);
      if (json == null) {
        println("JSONArray could not be parsed");
      } else {
        String species = json.getString(1);
        println(species);
      }
    }

    // Sketch prints:
    // Panthera pardus
Description | Takes a String, parses its contents, and returns a JSONArray. If the String does not contain JSONArray data or cannot be parsed, a null value is returned. parseJSONArray() is most useful when pulling data dynamically, such as from third-party APIs. Normally, API results would be saved to a String, and then can be converted to a structured JSONArray using parseJSONArray(). Be sure to check if null is returned before performing operations on the new JSONArray in case the String content could not be parsed. If your data already exists as a JSON file in the data folder, it is simpler to use loadJSONArray().
Syntax |
    parseJSONArray(input)
Parameters |
input | String: String to parse as a JSONArray
Returns | JSONArray
Related | JSONObject loadJSONObject() saveJSONObject()

Updated on January 1, 2021 03:38:07am EST
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.