{"record":{"id":"a5a9721e4c3c7508","repo":"QuantumNous/new-api","slug":"parameter-override-must-be-valid-json-format","errorCode":null,"errorMessage":"Parameter override must be valid JSON format","messagePattern":"Parameter override must be valid JSON format","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"web/src/features/channels/components/dialogs/param-override-editor-dialog.tsx","lineNumber":1483,"sourceCode":"          reorderOperations(prev, sourceId, operationId, position)\n        )\n        setSelectedOperationId(sourceId)\n      }\n      resetDragState()\n    },\n    [draggedOperationId, dragOverOperationId, dragOverPosition, resetDragState]\n  )\n\n  // ---------------------------------------------------------------------------\n  // Mode switching & templates\n  // ---------------------------------------------------------------------------\n\n  const buildVisualJson = useCallback((): string => {\n    if (visualMode === 'legacy') {\n      const trimmed = legacyValue.trim()\n      if (!trimmed) return ''\n      if (!verifyJSON(trimmed))\n        throw new Error(t('Parameter override must be valid JSON format'))\n      const parsed = JSON.parse(trimmed) as unknown\n      if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))\n        throw new Error(t('Legacy format must be a JSON object'))\n      return JSON.stringify(parsed, null, 2)\n    }\n    return buildOperationsJson(operations, { validate: true }, t)\n  }, [legacyValue, operations, t, visualMode])\n\n  const switchToJsonMode = useCallback(() => {\n    if (editMode === 'json') return\n    try {\n      setJsonText(buildVisualJson())\n      setJsonError('')\n    } catch (error) {\n      toast.error((error as Error).message)\n      if (visualMode === 'legacy') {\n        setJsonText(legacyValue)\n      } else {","sourceCodeStart":1465,"sourceCodeEnd":1501,"githubUrl":"https://github.com/QuantumNous/new-api/blob/e2c7aa7b102c2075eae2377df3508658d45e88dc/web/src/features/channels/components/dialogs/param-override-editor-dialog.tsx#L1465-L1501","documentation":"Thrown by buildVisualJson in the param-override editor when visualMode is 'legacy', the trimmed legacy text is non-empty, and verifyJSON(trimmed) returns false. It fires while converting the legacy text to JSON — e.g. in switchToJsonMode — and is surfaced via toast.error.","triggerScenarios":"User types or pastes a legacy override string like {model: 'gpt'} (unquoted key), trailing comma, or a stray quote, then switches edit mode to JSON; the pre-conversion syntax check fails before JSON.parse is even attempted.","commonSituations":"Copy-pasting override JSON from docs/wiki that uses smart quotes or comments; hand-editing JSON with single quotes; truncated paste leaving an unbalanced brace.","solutions":["Paste the legacy text into a JSON validator (jsonlint / editor JSON language mode) and fix the highlighted syntax error","Quote all keys and string values with double quotes; remove trailing commas and comments","If starting fresh, clear the legacy field (empty is allowed and returns '') and use visual mode to build the override","After fixing, switch modes again — the toast disappears once verifyJSON passes"],"exampleFix":"// before\n{model: \"gpt-4o\", temperature: 0.7,}\n// after\n{\n  \"model\": \"gpt-4o\",\n  \"temperature\": 0.7\n}","handlingStrategy":"validation","validationCode":"const trimmed = legacyValue.trim()\nconst isValidLegacyJson = !trimmed || verifyJSON(trimmed)\n// disable mode-switch/save button when !isValidLegacyJson","typeGuard":"const isParsableJson = (s: string): boolean => {\n  if (!s.trim()) return true\n  try { JSON.parse(s); return true } catch { return false }\n}","tryCatchPattern":"try {\n  setJsonText(buildVisualJson())\n  setJsonError('')\n} catch (error) {\n  toast.error((error as Error).message)\n}","preventionTips":["Validate as the user types (debounced verifyJSON) and show inline errors before mode switches","Keep the textarea in a JSON language mode so the editor flags syntax errors visually","Reject smart quotes and comments on paste with a normalizer"],"tags":["validation","json","param-override","editor","toast"],"backgroundTag":null,"analyzedSha":"e2c7aa7b102c2075eae2377df3508658d45e88dc","analyzedAt":"2026-08-15T10:35:18.111Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}