AykutSarac/jsoncrack.com · warning
Invalid Schema
Error message
Invalid Schema
What it means
Toast shown by the JSON Schema modal when the schema text cannot be parsed as JSON. onApply calls JSON.parse(schema) inside try/catch; any SyntaxError (or thrown primitive) routes to the catch with the generic 'Invalid Schema' message. The schema is not applied on failure.
Source
Thrown at apps/www/src/features/modals/SchemaModal/index.tsx:43
},
},
required: ["id"],
},
null,
2
)
);
const onApply = () => {
try {
const parsedSchema = JSON.parse(schema);
setJsonSchema(parsedSchema);
gaEvent("apply_json_schema");
toast.success("Applied schema!");
onClose();
} catch {
toast.error("Invalid Schema");
}
};
const onClear = () => {
setJsonSchema(null);
setSchema("");
toast("Disabled JSON Schema");
onClose();
};
return (
<Modal title="JSON Schema" size="lg" opened={opened} onClose={onClose} centered>
<Stack>
<Text fz="sm">Any validation failures are shown at the bottom toolbar of pane.</Text>
<Anchor
fz="sm"
target="_blank"
href="https://niem.github.io/json/sample-schema/"View on GitHub (pinned to 3c9af69e23)
Solutions
- Validate the schema with a JSON linter in the editor before applying.
- Run JSON.parse on the schema string in the console to get the exact SyntaxError position.
- Surface the caught SyntaxError message/position to the user instead of the generic text.
- Provide inline JSON validation feedback in the textarea (e.g. a parse-error marker).
Example fix
// before
} catch {
toast.error("Invalid Schema");
}
// after — show the parser's position
} catch (err) {
toast.error(err instanceof SyntaxError ? `Invalid Schema: ${err.message}` : "Invalid Schema");
} Defensive patterns
Strategy: validation
Validate before calling
// Validate schema parses before applying
export function tryParseSchema(text: string): { ok: true; value: unknown } | { ok: false; error: SyntaxError } {
try { return { ok: true, value: JSON.parse(text) }; }
catch (e) { return { ok: false, error: e as SyntaxError }; }
} Type guard
// Narrow the parse outcome
export function isSchemaValid(r: ReturnType<typeof tryParseSchema>): r is { ok: true; value: unknown } {
return r.ok;
} Try / catch
// Surface the parser's position instead of a generic message
const result = tryParseSchema(schema);
if (!result.ok) {
toast.error(`Invalid Schema: ${result.error.message}`);
return;
}
setJsonSchema(result.value); Prevention
- Run a JSON linter in the schema textarea.
- Catch and display the SyntaxError position to the user.
- Disable Apply until the schema parses.
When it happens
Trigger: Typing a schema with trailing commas, unquoted keys, unclosed braces, single quotes, comments, or any non-strict-JSON content in the textarea, then clicking Apply.
Common situations: Pasting a schema written in JSON5/JS object literal syntax; an incomplete edit; copying a schema that uses // comments; a copy-paste that drops a brace.
Related errors
- error.message
- errors[0]?.message
- Failed to parse data (${syntaxErrorCount} syntax error(s)).
- Unable to parse data.
- Failed to fetch JSON!
AI-assisted analysis of AykutSarac/jsoncrack.com@3c9af69e23 (2026-08-12).
Data as JSON: /api/errors/184ecf2a1f176714.
Report an issue: GitHub.