Skip to content

Commit 4067303

Browse files
authored
Merge pull request #1 from devforth/feature/AdminForth/1704/create-json-editor-plugin
fix: add string trimmed support
2 parents fbbe0f0 + 1bd9adc commit 4067303

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

custom/JsonEditor.vue

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,16 @@ function toDisplay(v: any): string {
7575
return JSON.stringify(v);
7676
}
7777
78-
function isValidJson(raw: string): boolean {
79-
if (!raw.trim()) return true;
78+
function fromDisplay(raw: string): any {
79+
const trimmed = raw.trim();
80+
if (!trimmed) return '';
8081
try {
81-
JSON.parse(raw.trim());
82-
return true;
82+
return JSON.parse(trimmed);
8383
} catch {
84-
return false;
84+
return trimmed;
8585
}
8686
}
8787
88-
function fromDisplay(raw: string): any {
89-
if (!raw.trim()) return '';
90-
return JSON.parse(raw.trim());
91-
}
92-
9388
function toPairs(json: any): Pair[] {
9489
let obj: any;
9590
if (typeof json === 'string') {
@@ -116,10 +111,6 @@ function getError(): string | null {
116111
if (new Set(keys).size < keys.length) {
117112
return 'Duplicate keys are not allowed';
118113
}
119-
const badIndex = pairs.value.findIndex((p: Pair) => p.key.trim() && !isValidJson(p.value));
120-
if (badIndex !== -1) {
121-
return `Row ${badIndex + 1}: value is not valid JSON`;
122-
}
123114
return null;
124115
}
125116

0 commit comments

Comments
 (0)