Skip to content

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

feat: don't create an empty node in a root array

victorbrambati36fcb6f55b7a
diff --git a/src/utils/jsonParser.ts b/src/utils/jsonParser.ts
index 66f88eba..4b070975 100644
--- a/src/utils/jsonParser.ts
+++ b/src/utils/jsonParser.ts
@@ -302,30 +302,34 @@ export const parser = (jsonStr: string, isFolded = false) => {
}
}
};
+
if (json) {
traverse(json);
- }
- if (notHaveParent.length > 1) {
- const text = "";
- const { width, height } = calculateSize(text, false, isFolded);
- const emptyId = addNodes(text, width, height, false, true);
- notHaveParent.forEach(children => {
- addEdges(emptyId, children);
- });
- }
- if (nodes.length === 0 && json) {
- if (json.type === "array") {
- const text = "[]";
- const { width, height } = calculateSize(text, false, isFolded);
- addNodes(text, width, height, false);
- } else {
- const text = "{}";
- const { width, height } = calculateSize(text, false, isFolded);
- addNodes(text, width, height, false);
+
+ if (notHaveParent.length > 1) {
+ if (json.type !== "array") {
+ const text = "";
+ const { width, height } = calculateSize(text, false, isFolded);
+ const emptyId = addNodes(text, width, height, false, true);
+ notHaveParent.forEach(children => {
+ addEdges(emptyId, children);
+ });
+ }
+ }
+
+ if (nodes.length === 0) {
+ if (json.type === "array") {
+ const text = "[]";
+ const { width, height } = calculateSize(text, false, isFolded);
+ addNodes(text, width, height, false);
+ } else {
+ const text = "{}";
+ const { width, height } = calculateSize(text, false, isFolded);
+ addNodes(text, width, height, false);
+ }
}
}
- console.log(nodes);
return { nodes, edges };
} catch (error) {
console.error(error);