Skip to content

Commit 458e51b

Browse files
authored
Merge pull request #104 from ashphy/ashphy/issue99
feat: Ignore json with comment
2 parents 19ff625 + 06356b6 commit 458e51b

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"clsx": "^2.1.1",
3030
"cmdk": "^1.1.1",
3131
"jotai": "^2.14.0",
32+
"jsonc-parser": "^3.3.1",
3233
"jsonpath-js": "^0.3.0",
3334
"jsonpath-plus": "^10.3.0",
3435
"lucide-react": "^0.544.0",
@@ -63,4 +64,4 @@
6364
"vite": "^7.1.5",
6465
"vitest": "^3.2.4"
6566
}
66-
}
67+
}

src/components/editor/json-editor.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export const JSONEditor = () => {
2424
}, [document]);
2525

2626
const handleEditorDidMount: OnMount = async (editor, monaco) => {
27+
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
28+
validate: true,
29+
allowComments: true,
30+
trailingCommas: "ignore",
31+
});
2732
monaco.languages.registerHoverProvider("json", {
2833
provideHover(model, position) {
2934
// Hover normalized path on the document only

src/hooks/use-jsonpath.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { compress, decompress } from "@/lib/compress";
88
import { useCallback, useEffect } from "react";
99
import { Session, SessionSchema } from "@/types/session";
1010
import * as v from "valibot";
11+
import { parse } from "jsonc-parser";
1112

1213
const STORAGE_KEY_SESSION = "joe-session";
1314

@@ -103,7 +104,7 @@ const sessionAtom = atom<Session>((get) => ({
103104

104105
const jsonDocumentAtom = atom<JSONDocument>((get) => {
105106
try {
106-
const jsonDocument = JSON.parse(get(documentAtom)) as JSONValue;
107+
const jsonDocument = parse(get(documentAtom)) as JSONValue;
107108
return {
108109
json: jsonDocument,
109110
error: undefined,

0 commit comments

Comments
 (0)