- 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 | ### JSONObject
Examples |
    JSONObject json;

    void setup() {

      json = new JSONObject();

      json.setInt("id", 0);
      json.setString("species", "Panthera leo");
      json.setString("name", "Lion");

      saveJSONObject(json, "data/new.json");
    }

    // Sketch saves the following to a file called "new.json":
    // {
    //   "id": 0,
    //   "species": "Panthera leo",
    //   "name": "Lion"
    // }
Description | A JSONObject stores JSON data with multiple name/value pairs. Values can be numeric, Strings, booleans, other JSONObjects or JSONArrays, or null. JSONObject and JSONArray objects are quite similar and share most of the same methods; the primary difference is that the latter stores an array of JSON objects, while the former represents a single JSON object. JSON can be generated from scratch, dynamically, or using data from an existing file. JSON can also be output and saved to disk, as in the example above.
Methods |
getString() | Gets the string value associated with a key
getInt() | Gets the int value associated with a key
getFloat() | Gets the float value associated with a key
getBoolean() | Gets the boolean value associated with a key
getJSONArray() | Gets the JSONArray value associated with a key
getJSONObject() | Gets the JSONObject value associated with a key
isNull() | Determine if the value associated with the key is null or if there is no value.
setString() | Put a key/String pair in the JSONObject
setInt() | Put a key/int pair in the JSONObject
setFloat() | Put a key/float pair in the JSONObject
setBoolean() | Put a key/boolean pair in the JSONObject
setJSONObject() | Sets the JSONObject value associated with a key
setJSONArray() | Sets the JSONArray value associated with a key
Related | JSONArray loadJSONObject() loadJSONArray() saveJSONObject() saveJSONArray()

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