Skip to content

Commit ea0ac61

Browse files
authored
fix(jsonc): add trailing comma support (#16)
Signed-off-by: assagman <ahmetsercansagman@gmail.com>
1 parent fa537a1 commit ea0ac61

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/services/jsonc.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* Strips comments from JSONC content while respecting string boundaries.
33
* Handles // and /* comments, URLs in strings, and escaped quotes.
4+
* Also removes trailing commas to support more relaxed JSONC format.
45
*/
56
export function stripJsoncComments(content: string): string {
67
let result = "";
@@ -79,5 +80,6 @@ export function stripJsoncComments(content: string): string {
7980
i++;
8081
}
8182

82-
return result;
83+
// Remove trailing commas before } or ]
84+
return result.replace(/,\s*([}\]])/g, "$1");
8385
}

0 commit comments

Comments
 (0)