Skip to content

Commit 61ea78a

Browse files
committed
fixing the json parser
1 parent 2e9bde2 commit 61ea78a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/context/RequestContext.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ export const RequestProvider = ({ children }: { children: ReactNode }) => {
6363

6464
const formatJson = () => {
6565
try {
66-
const parsed = JSON.parse(payload);
66+
const sanitized = payload.replace(/[]/g, '"').replace(/[]/g, "'");
67+
68+
const parsed = JSON.parse(sanitized);
6769
setPayload(JSON.stringify(parsed, null, 2));
6870
} catch (error) {
6971
console.error("Invalid JSON");
72+
alert("Invalid JSON format. Please correct it before formatting.");
7073
}
7174
};
7275

0 commit comments

Comments
 (0)