{"record":{"id":"4425158dd41d6e30","repo":"Activiti/Activiti","slug":"jsonobject-quote-key-is-not-a-jsonarray","errorCode":null,"errorMessage":"JSONObject[\" + quote(key) + \"] is not a JSONArray.","messagePattern":"JSONObject\\[\" \\+ quote\\(key\\) \\+ \"\\] is not a JSONArray\\.","errorType":"exception","errorClass":"JSONException","httpStatus":null,"severity":"error","filePath":"activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/util/json/JSONObject.java","lineNumber":452,"sourceCode":"            throw new JSONException(\"JSONObject[\" + quote(key) + \"] is not an int.\");\n        }\n    }\n\n    /**\n     * Get the JSONArray value associated with a key.\n     *\n     * @param key\n     *          A key string.\n     * @return A JSONArray which is the value.\n     * @throws JSONException\n     *           if the key is not found or if the value is not a JSONArray.\n     */\n    public JSONArray getJSONArray(String key) throws JSONException {\n        Object o = get(key);\n        if (o instanceof JSONArray) {\n            return (JSONArray) o;\n        }\n        throw new JSONException(\"JSONObject[\" + quote(key) + \"] is not a JSONArray.\");\n    }\n\n    /**\n     * Get the JSONObject value associated with a key.\n     *\n     * @param key\n     *          A key string.\n     * @return A JSONObject which is the value.\n     * @throws JSONException\n     *           if the key is not found or if the value is not a JSONObject.\n     */\n    public JSONObject getJSONObject(String key) throws JSONException {\n        Object o = get(key);\n        if (o instanceof JSONObject) {\n            return (JSONObject) o;\n        }\n        throw new JSONException(\"JSONObject[\" + quote(key) + \"] is not a JSONObject.\");\n    }","sourceCodeStart":434,"sourceCodeEnd":470,"githubUrl":"https://github.com/Activiti/Activiti/blob/56435b1a97deeafdc09dd40074b056c89fba5a8a/activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/util/json/JSONObject.java#L434-L470","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nJSONArray list = config.getJSONArray(\"variables\");\n// after\nObject o = config.opt(\"variables\");\nJSONArray list;\nif (o instanceof JSONArray) {\n    list = (JSONArray) o;\n} else if (o != null) {\n    list = new JSONArray().put(o);\n} else {\n    list = new JSONArray();\n}","handlingStrategy":"type-guard","validationCode":"Object o = obj.opt(key); boolean ok = o instanceof JSONArray;","typeGuard":"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(); }","tryCatchPattern":"try { JSONArray a = obj.getJSONArray(key); } catch (JSONException e) { a = new JSONArray(); }","preventionTips":["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"],"tags":["json","type-mismatch","array"],"backgroundTag":"type-mismatch","analyzedSha":"56435b1a97deeafdc09dd40074b056c89fba5a8a","analyzedAt":"2026-09-09T21:00:06.703Z","contentChangedAt":"2026-09-09T21:00:06.703Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}