Skip to content

✨ Innovative and open-source visualization application that transforms various data formats, such as JSON, YAML, XML and CSV into interactive graphs.

fix: allow json with comments

AykutSaraca871ee9a73e4
diff --git a/src/lib/utils/json/jsonAdapter.ts b/src/lib/utils/json/jsonAdapter.ts
index 75be48dd..8b84567d 100644
--- a/src/lib/utils/json/jsonAdapter.ts
+++ b/src/lib/utils/json/jsonAdapter.ts
@@ -1,5 +1,6 @@
import { load, dump } from "js-yaml";
import { csv2json, json2csv } from "json-2-csv";
+import { parse } from "jsonc-parser";
import jxon from "jxon";
import toml from "toml";
import { FileFormat } from "src/types/models";
@@ -34,7 +35,7 @@ const contentToJson = async (value: string, format = FileFormat.JSON): Promise<o
try {
let json: object = {};
- if (format === FileFormat.JSON) json = JSON.parse(value);
+ if (format === FileFormat.JSON) json = parse(value);
if (format === FileFormat.YAML) json = load(value) as object;
if (format === FileFormat.XML) json = jxon.stringToJs(value);
if (format === FileFormat.TOML) json = toml.parse(value);
@@ -53,10 +54,10 @@ const jsonToContent = async (json: string, format: FileFormat): Promise<string>
if (!json) return json;
if (format === FileFormat.JSON) contents = json;
- if (format === FileFormat.YAML) contents = dump(JSON.parse(json));
- if (format === FileFormat.XML) contents = dump(JSON.parse(json));
- if (format === FileFormat.TOML) contents = dump(JSON.parse(json));
- if (format === FileFormat.CSV) contents = await json2csv(JSON.parse(json));
+ if (format === FileFormat.YAML) contents = dump(parse(json));
+ if (format === FileFormat.XML) contents = dump(parse(json));
+ if (format === FileFormat.TOML) contents = dump(parse(json));
+ if (format === FileFormat.CSV) contents = await json2csv(parse(json));
return Promise.resolve(contents);
} catch (error: any) {