AykutSarac/jsoncrack.com · warning
error.message
Error message
error.message
What it means
In JPathModal.evaluteJsonPath, the catch surfaces the thrown error's message directly as a toast. The try runs getJson() (current editor JSON), JSON.parse(json), then jsonpath-plus JSONPath({ path: query, json }). Any failure — invalid JSON in the editor or an invalid JSONPath expression — is shown to the user via error.message. There is no fallback string; an empty/garbled thrown message would produce an empty toast.
Source
Thrown at apps/www/src/features/modals/JPathModal/index.tsx:25
import { VscLinkExternal } from "react-icons/vsc";
import useFile from "../../../store/useFile";
import useJson from "../../../store/useJson";
export const JPathModal = ({ opened, onClose }: ModalProps) => {
const getJson = useJson(state => state.getJson);
const setContents = useFile(state => state.setContents);
const [query, setQuery] = React.useState("");
const evaluteJsonPath = () => {
try {
const json = getJson();
const result = JSONPath({ path: query, json: JSON.parse(json) });
setContents({ contents: JSON.stringify(result, null, 2) });
gaEvent("run_json_path");
onClose();
} catch (error) {
if (error instanceof Error) toast.error(error.message);
}
};
return (
<Modal title="JSON Path" size="lg" opened={opened} onClose={onClose} centered>
<Stack>
<Text fz="sm">
JsonPath expressions always refer to a JSON structure in the same way as XPath expression
are used in combination with an XML document. The "root member object" in
JsonPath is always referred to as $ regardless if it is an object or array.
<br />
<Anchor
fz="sm"
target="_blank"
href="https://docs.oracle.com/cd/E60058_01/PDF/8.0.8.x/8.0.8.0.0/PMF_HTML/JsonPath_Expressions.htm"
rel="noopener noreferrer"
>
Read documentation. <VscLinkExternal />View on GitHub (pinned to 3c9af69e23)
Solutions
- Validate the editor content is parseable JSON before enabling Run (or pre-check with JSON.parse).
- Validate the JSONPath query syntax against a known-good expression or a linter.
- Provide example queries in the modal to reduce syntax errors.
- Guard against non-Error throws so the toast is never empty.
Example fix
// before
} catch (error) {
if (error instanceof Error) toast.error(error.message);
}
// after — never show an empty message
} catch (error) {
toast.error(error instanceof Error && error.message ? error.message : "Invalid JSONPath query or JSON.");
} Defensive patterns
Strategy: validation
Validate before calling
// Validate JSON and JSONPath syntax before running
export function canRunJsonPath(json: string, query: string): boolean {
try { JSON.parse(json); return typeof query === "string" && query.trim().length > 0; }
catch { return false; }
} Type guard
// Ensure the thrown value carries a usable message
export function hasMessage(e: unknown): e is Error {
return e instanceof Error && typeof e.message === "string" && e.message.length > 0;
} Try / catch
// Never show an empty toast
} catch (error) {
toast.error(hasMessage(error) ? error.message : "Invalid JSONPath query or JSON.");
} Prevention
- Validate the editor JSON parses before enabling Run.
- Provide example JSONPath queries in the modal.
- Guard against non-Error throws so the toast is never blank.
When it happens
Trigger: Typing an invalid JSONPath query (e.g. `$.#`, malformed brackets `$.[`, unclosed filter `$..[?(@.price>`), or running the query when the editor content is not valid JSON (JSON.parse throws).
Common situations: User experimentation with JSONPath syntax; running a path against partially-edited/invalid JSON; quoting/bracket mistakes in filter expressions.
Related errors
- Failed to parse data (${syntaxErrorCount} syntax error(s)).
- Unable to parse data.
- Invalid Schema
- Unable to process the request.
- Failed to fetch JSON!
AI-assisted analysis of AykutSarac/jsoncrack.com@3c9af69e23 (2026-08-12).
Data as JSON: /api/errors/06ad6353c183c817.
Report an issue: GitHub.