{"record":{"id":"e88379fed9f97a13","repo":"googleapis/mcp-toolbox","slug":"input-for-paramname-must-be-a-json-array-e-g","errorCode":null,"errorMessage":"Input for ${paramName} must be a JSON array (e.g., [\"a\", \"b\"]).","messagePattern":"Input for (.+?) must be a JSON array \\(e\\.g\\., \\[\"a\", \"b\"\\]\\)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"internal/server/static/js/runTool.js","lineNumber":138,"sourceCode":"/**\n * Parses and validates a single array parameter from a raw string value.\n * @param {string} rawValue The raw string value from FormData.\n * @param {string} valueType The full array type string (e.g., \"array<number>\").\n * @param {string} paramName The name of the parameter for error messaging.\n * @return {!Array<*>} The parsed array.\n * @throws {Error} If parsing or type validation fails.\n */\nfunction parseArrayParameter(rawValue, valueType, paramName) {\n    const ELEMENT_TYPE = valueType.substring(6, valueType.length - 1);\n    let parsedArray;\n    try {\n        parsedArray = JSON.parse(rawValue);\n    } catch (e) {\n        throw new Error(`Invalid JSON format for ${paramName}. Expected an array. ${e.message}`);\n    }\n\n    if (!Array.isArray(parsedArray)) {\n        throw new Error(`Input for ${paramName} must be a JSON array (e.g., [\"a\", \"b\"]).`);\n    }\n\n    return parsedArray.map((item, index) => {\n        switch (ELEMENT_TYPE) {\n            case 'number':\n                const NUM = Number(item);\n                if (isNaN(NUM)) {\n                    throw new Error(`Invalid number \"${item}\" found in array for ${paramName} at index ${index}.`);\n                }\n                return NUM;\n            case 'boolean':\n                return item === true || String(item).toLowerCase() === 'true';\n            case 'string':\n            default:\n                return item;\n        }\n    });\n}","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/server/static/js/runTool.js#L120-L156","documentation":"A \"mapValue\" must be a map containing a \"fields\" key whose value is itself a map. If the shape check fails, this error is returned. This mirrors Firestore's REST representation of maps.","triggerScenarios":"Passing {\"mapValue\": {\"a\": 1}} (fields directly under mapValue without the \"fields\" key), {\"mapValue\": {\"fields\": [1,2]}} (fields is an array), or {\"mapValue\": 42} (not a map).","commonSituations":"Hand-built payloads omitting the \"fields\" wrapper; nested objects serialized from structs that don't match Firestore's REST shape.","solutions":["Nest the fields: {\"mapValue\": {\"fields\": {<name>: <typedValue>}}}.","Ensure \"fields\" is a JSON object, not an array or scalar.","Alternatively pass a plain Go map (without the typed wrapper) and let convertPlainMap handle it via the default branch."],"exampleFix":"// before\n{\"mapValue\": {\"a\": 1}}\n// after\n{\"mapValue\": {\"fields\": {\"a\": {\"integerValue\": 1}}}}","handlingStrategy":"type-guard","validationCode":"func validMapValue(v any) bool {\n    m, ok := v.(map[string]any); if !ok { return false }\n    _, ok = m[\"fields\"].(map[string]any); return ok\n}","typeGuard":"func asMapValue(v any) (map[string]any, bool) {\n    m, ok := v.(map[string]any); if !ok { return nil, false }\n    f, ok := m[\"fields\"].(map[string]any); return f, ok\n}","tryCatchPattern":"if _, err := JSONToFirestoreValue(val, client); err != nil {\n    if strings.Contains(err.Error(), \"invalid map value format\") { /* nest fields under \"fields\" */ }\n}","preventionTips":["Always nest map fields under the \"fields\" key","Ensure \"fields\" is a JSON object, not an array","Consider passing plain maps so convertPlainMap handles them"],"tags":["firestore","map","shape-validation"],"backgroundTag":"invalid-map-value-format","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}