MCPcopy Create free account
hub / github.com/triggerdotdev/jsonhero-web / generateChildren

Function generateChildren

app/hooks/useJsonTree.tsx:99–135  ·  view source on GitHub ↗
(
  info: JSONValueType,
  path: JSONHeroPath
)

Source from the content-addressed store, hash-verified

97}
98
99function generateChildren(
100 info: JSONValueType,
101 path: JSONHeroPath
102): Array<JsonTreeViewNode> | undefined {
103 if (info.name === "array") {
104 return info.value.map((item, index) => {
105 const itemInfo = inferType(item);
106 const itemPath = path.child(index.toString());
107
108 return {
109 id: itemPath.toString(),
110 name: index.toString(),
111 title: index.toString(),
112 longTitle: `Index ${index.toString()}`,
113 subtitle: formatValue(itemInfo),
114 icon: iconForType(itemInfo),
115 children: generateChildren(itemInfo, itemPath),
116 };
117 });
118 }
119
120 if (info.name === "object") {
121 return Object.entries(info.value).map(([key, value]) => {
122 const cleanKey = key.replace(/\./g, "\\.");
123 const itemInfo = inferType(value);
124 const itemPath = path.child(cleanKey);
125 return {
126 id: itemPath.toString(),
127 name: key,
128 title: key,
129 subtitle: formatValue(itemInfo),
130 icon: iconForType(itemInfo),
131 children: generateChildren(itemInfo, itemPath),
132 };
133 });
134 }
135}

Callers 1

generateTreeViewNodesFunction · 0.70

Calls 2

formatValueFunction · 0.90
iconForTypeFunction · 0.90

Tested by

no test coverage detected