Activiti/Activiti · error · JSONException
JSONObject[" + quote(key) + "] is not a JSONArray.
Error message
JSONObject[" + quote(key) + "] is not a JSONArray.
What it means
Thrown by JSONObject.getJSONArray when the value stored under the requested key exists but is not a JSONArray (or the key is missing), so the typed access is impossible — a JSON type mismatch rather than a syntax error.
Solutions
- Check opt(key) instanceof JSONArray before casting; wrap a lone non-array value into a new JSONArray if you want tolerant reading.
- Use a helper that normalizes 'object or array' fields to a list.
- Fix the producer so the field is always an array.
- Wrap in try-catch (JSONException) and treat as empty list.
Example fix
// before
JSONArray list = config.getJSONArray("variables");
// after
Object o = config.opt("variables");
JSONArray list;
if (o instanceof JSONArray) {
list = (JSONArray) o;
} else if (o != null) {
list = new JSONArray().put(o);
} else {
list = new JSONArray();
} Defensive patterns
Strategy: type-guard
Validate before calling
Object o = obj.opt(key); boolean ok = o instanceof JSONArray;
Type guard
JSONArray arrayOrWrapped(JSONObject obj, String key) { Object o = obj.opt(key); if (o instanceof JSONArray) return (JSONArray) o; if (o != null) return new JSONArray().put(o); return new JSONArray(); } Try / catch
try { JSONArray a = obj.getJSONArray(key); } catch (JSONException e) { a = new JSONArray(); } Prevention
- Guard with opt(key) instanceof JSONArray before getJSONArray
- Normalize 'single object vs array' API fields at parse time
- Ensure producers always emit arrays for list-typed fields
When it happens
Trigger: Calling getJSONArray(key) where the stored value is a scalar, JSONObject, or JSONObject.NULL — e.g. a field that was a list in one payload version but a single object/string in another.
Common situations: JSON APIs that collapse single-element collections to a bare object; schema drift between process engine versions reading job/variable configuration; typo'd keys pointing at scalar fields.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- JSONArray[" + index + "] is not a JSONObject.
- JSONArray[" + index + "] is not a Boolean.
- JSONArray[" + index + "] is not a JSONArray.
- JSONArray[" + index + "] is not a number.
- JSONObject[" + key + "] is not a JSONArray.
AI-assisted analysis of Activiti/Activiti@56435b1a97 (2026-09-09).
Data as JSON: /api/errors/4425158dd41d6e30.
Report an issue: GitHub.
Appendix: source
Thrown at activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/util/json/JSONObject.java:452
throw new JSONException("JSONObject[" + quote(key) + "] is not an int.");
}
}
/**
* Get the JSONArray value associated with a key.
*
* @param key
* A key string.
* @return A JSONArray which is the value.
* @throws JSONException
* if the key is not found or if the value is not a JSONArray.
*/
public JSONArray getJSONArray(String key) throws JSONException {
Object o = get(key);
if (o instanceof JSONArray) {
return (JSONArray) o;
}
throw new JSONException("JSONObject[" + quote(key) + "] is not a JSONArray.");
}
/**
* Get the JSONObject value associated with a key.
*
* @param key
* A key string.
* @return A JSONObject which is the value.
* @throws JSONException
* if the key is not found or if the value is not a JSONObject.
*/
public JSONObject getJSONObject(String key) throws JSONException {
Object o = get(key);
if (o instanceof JSONObject) {
return (JSONObject) o;
}
throw new JSONException("JSONObject[" + quote(key) + "] is not a JSONObject.");
}View on GitHub (pinned to 56435b1a97)