Zie619/n8n-workflows · warning · Error

The JSON is not an array.

Error message

The JSON is not an array.

What it means

Same 'Parse and Chunk JSON Data' node replicated in workflow 1747. It throws 'The JSON is not an array.' when the LLM text parses to a non-array JSON value; the catch then returns [{json:{error}}], so the message usually travels as data into the downstream SerpAPI request rather than failing the execution.

Source

Thrown at workflows/Http/1747_HTTP_Stickynote_Automate_Webhook.json:102

      "credentials": {
        "openRouterApi": {
          "id": "WZWYWCfluxuKxZzV",
          "name": "OpenRouter account"
        }
      },
      "typeVersion": 1,
      "notes": "This lmChatOpenRouter node performs automated tasks as part of the workflow."
    },
    {
      "id": "4ab360eb-858f-48b8-a00d-71867d4f0c93",
      "name": "Parse and Chunk JSON Data",
      "type": "n8n-nodes-base.code",
      "position": [
        -1420,
        160
      ],
      "parameters": {
        "jsCode": "// Parse the input JSON string and split it into four chunks\nconst rawText = $json.text;\n\n// Remove Markdown JSON code blocks if present\nconst cleanedText = rawText.replace(/```json|```/g, '').trim();\n\ntry {\n    const jsonArray = JSON.parse(cleanedText);\n    if (!Array.isArray(jsonArray)) {\n        throw new Error('The JSON is not an array.');\n    }\n    const chunkSize = Math.ceil(jsonArray.length / 4);\n    const chunks = [];\n    for (let i = 0; i < jsonArray.length; i += chunkSize) {\n        chunks.push(jsonArray.slice(i, i + chunkSize));\n    }\n    return chunks.map(chunk => ({ json: { chunk } }));\n} catch (error) {\n    return [{ json: { error: error.message } }];\n}\n"
      },
      "typeVersion": 2,
      "notes": "This code node performs automated tasks as part of the workflow."
    },
    {
      "id": "5a3ac393-8355-449f-93cb-b98e8bee9b80",
      "name": "Perform SerpAPI Search Request",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -780,
        180
      ],
      "parameters": {
        "url": "{{ $env.API_BASE_URL }}",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [

View on GitHub (pinned to 94007c1445)

Solutions

  1. Make the upstream prompt demand a top-level JSON array only (no object wrapper, no commentary).
  2. Add envelope unwrapping before the Array.isArray check (see exampleFix).
  3. Branch on the error item downstream so a bad LLM reply cannot become a SerpAPI query.
  4. Pin a known-good LLM response for testing the chunking logic in isolation.

Example fix

// before
const jsonArray = JSON.parse(cleanedText);
if (!Array.isArray(jsonArray)) {
    throw new Error('The JSON is not an array.');
}

// after
let parsed = JSON.parse(cleanedText);
if (parsed && !Array.isArray(parsed) && typeof parsed === 'object') {
  const arrays = Object.values(parsed).filter(Array.isArray);
  if (arrays.length === 1) parsed = arrays[0];
}
if (!Array.isArray(parsed)) {
    throw new Error('The JSON is not an array.');
}
const jsonArray = parsed;
Defensive patterns

Strategy: validation

Validate before calling

const cleaned = String($json.text ?? '').replace(/```json|```/g, '').trim();
const parsed = JSON.parse(cleaned);
const arr = Array.isArray(parsed) ? parsed : Object.values(parsed).find(Array.isArray);
if (!arr) throw new Error('The JSON is not an array.');

Type guard

function unwrapLlmArray(parsed) {
  if (Array.isArray(parsed)) return parsed;
  if (parsed && typeof parsed === 'object') {
    const arrays = Object.values(parsed).filter(Array.isArray);
    if (arrays.length === 1) return arrays[0];
  }
  return null;
}

Prevention

When it happens

Trigger: The lmChatOpenRouter node returns a JSON object (results wrapper, error object) or scalar instead of a top-level array, and Array.isArray(jsonArray) is false after successful JSON.parse.

Common situations: Prompt asks for 'JSON' but not specifically an array; different OpenRouter model honoring the format differently; the two workflows drifting so 1747's prompt is weaker than 1580's; long outputs getting truncated into a valid-but-wrong shape.

Related errors


AI-assisted analysis of Zie619/n8n-workflows@94007c1445 (2026-08-15). Data as JSON: /api/errors/a13353db24a87d43. Report an issue: GitHub.