Auto-fix JSON comments and trailing commas for HTTP request bodies

Add a per-request "Automatically Fix JSON" toggle (default: on) that strips
comments and trailing commas before sending HTTP requests. When disabled,
comments are sent as-is and the editor linter flags them as errors.

- New JsonBodyEditor component with settings dropdown and dismissible banner
- Configurable JSON linter (allowComments/allowTrailingCommas) via lintExtension prop
- strip_trailing_commas pass in Rust strip_json_comments pipeline
- Fix JSON formatter pulling standalone comments onto previous comma line
- Add get_bool_map helper, maybe_strip_json_comments, and related tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Gregory Schier
2026-03-05 13:23:41 -08:00
parent ed6f9f8bd0
commit c340a7d5ae
11 changed files with 355 additions and 30 deletions

View File

@@ -4,14 +4,22 @@ import { parse as jsonLintParse } from '@prantlf/jsonlint';
const TEMPLATE_SYNTAX_REGEX = /\$\{\[[\s\S]*?]}/g;
export function jsonParseLinter() {
interface JsonLintOptions {
allowComments?: boolean;
allowTrailingCommas?: boolean;
}
export function jsonParseLinter(options?: JsonLintOptions) {
return (view: EditorView): Diagnostic[] => {
try {
const doc = view.state.doc.toString();
// We need lint to not break on stuff like {"foo:" ${[ ... ]}} so we'll replace all template
// syntax with repeating `1` characters, so it's valid JSON and the position is still correct.
const escapedDoc = doc.replace(TEMPLATE_SYNTAX_REGEX, (m) => '1'.repeat(m.length));
jsonLintParse(escapedDoc, { mode: 'cjson' });
jsonLintParse(escapedDoc, {
mode: (options?.allowComments ?? true) ? 'cjson' : 'json',
ignoreTrailingCommas: options?.allowTrailingCommas ?? false,
});
// biome-ignore lint/suspicious/noExplicitAny: none
} catch (err: any) {
if (!('location' in err)) {