From 3e176f579a8369b0e73d162b61fa6f705bd90551 Mon Sep 17 00:00:00 2001 From: Nalla Prakash <81852531+prakashNalla@users.noreply.github.com> Date: Sat, 31 Oct 2026 09:07:24 +0530 Subject: [PATCH] fix(json-formatter): accept JSON5 in Validate when JSON5 is on --- .../json-formatter/JsonFormatterClient.test.tsx | 11 +++++++++++ app/(tools)/json-formatter/JsonFormatterClient.tsx | 5 +++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/(tools)/json-formatter/JsonFormatterClient.test.tsx b/app/(tools)/json-formatter/JsonFormatterClient.test.tsx index 4eaae83..8a29723 100644 --- a/app/(tools)/json-formatter/JsonFormatterClient.test.tsx +++ b/app/(tools)/json-formatter/JsonFormatterClient.test.tsx @@ -121,6 +121,17 @@ describe("JsonFormatterClient", () => { await waitFor(() => expect(inputEl().value).toBe('{\n "a": 1,\n "b": 2\n}')); expect(screen.queryByText("Invalid JSON")).not.toBeInTheDocument(); }); + + it("validates JSON5 input", async () => { + renderClient(); + + toggleJson5(); + typeInput("{b: 2, a: 1,}"); + fireEvent.click(screen.getByRole("button", { name: "Validate" })); + + expect(await screen.findByText("Valid JSON ✓")).toBeInTheDocument(); + expect(screen.queryByText("Invalid JSON")).not.toBeInTheDocument(); + }); }); describe("Fetch from URL", () => { diff --git a/app/(tools)/json-formatter/JsonFormatterClient.tsx b/app/(tools)/json-formatter/JsonFormatterClient.tsx index 5ea48b9..117c84b 100644 --- a/app/(tools)/json-formatter/JsonFormatterClient.tsx +++ b/app/(tools)/json-formatter/JsonFormatterClient.tsx @@ -120,7 +120,8 @@ export function JsonFormatterClient() { }, [input, strictInput, push, history]); const doValidate = useCallback(() => { - const r = validate(input); + const strict = strictInput(); + const r = strict.ok ? validate(strict.value) : strict; if (r.ok) { setError(null); push("Valid JSON ✓", "success"); @@ -129,7 +130,7 @@ export function JsonFormatterClient() { setErrorShake((n) => n + 1); push("Invalid JSON", "error"); } - }, [input, push]); + }, [strictInput, push]); const doSort = useCallback(() => { const strict = strictInput();