QuantumNous/new-api · warning · Error
Parameter override must be valid JSON format
Error message
Parameter override must be valid JSON format
What it means
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.
Source
Thrown at web/src/features/channels/components/dialogs/param-override-editor-dialog.tsx:1483
reorderOperations(prev, sourceId, operationId, position)
)
setSelectedOperationId(sourceId)
}
resetDragState()
},
[draggedOperationId, dragOverOperationId, dragOverPosition, resetDragState]
)
// ---------------------------------------------------------------------------
// Mode switching & templates
// ---------------------------------------------------------------------------
const buildVisualJson = useCallback((): string => {
if (visualMode === 'legacy') {
const trimmed = legacyValue.trim()
if (!trimmed) return ''
if (!verifyJSON(trimmed))
throw new Error(t('Parameter override must be valid JSON format'))
const parsed = JSON.parse(trimmed) as unknown
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
throw new Error(t('Legacy format must be a JSON object'))
return JSON.stringify(parsed, null, 2)
}
return buildOperationsJson(operations, { validate: true }, t)
}, [legacyValue, operations, t, visualMode])
const switchToJsonMode = useCallback(() => {
if (editMode === 'json') return
try {
setJsonText(buildVisualJson())
setJsonError('')
} catch (error) {
toast.error((error as Error).message)
if (visualMode === 'legacy') {
setJsonText(legacyValue)
} else {View on GitHub (pinned to e2c7aa7b10)
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
Example fix
// before
{model: "gpt-4o", temperature: 0.7,}
// after
{
"model": "gpt-4o",
"temperature": 0.7
} Defensive patterns
Strategy: validation
Validate before calling
const trimmed = legacyValue.trim() const isValidLegacyJson = !trimmed || verifyJSON(trimmed) // disable mode-switch/save button when !isValidLegacyJson
Type guard
const isParsableJson = (s: string): boolean => {
if (!s.trim()) return true
try { JSON.parse(s); return true } catch { return false }
} Try / catch
try {
setJsonText(buildVisualJson())
setJsonError('')
} catch (error) {
toast.error((error as Error).message)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Legacy format must be a JSON object
- JSON must be an object
- Channel is not selected
- Unexpected release payload
AI-assisted analysis of QuantumNous/new-api@e2c7aa7b10 (2026-08-15).
Data as JSON: /api/errors/a5a9721e4c3c7508.
Report an issue: GitHub.