MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / jsonReconstruct

Function jsonReconstruct

lib/utils.ts:294–318  ·  view source on GitHub ↗
(chunks: Chunk[])

Source from the content-addressed store, hash-verified

292}
293
294export function jsonReconstruct(chunks: Chunk[]): Record<string, any> {
295 /**
296 Takes Chunks outputted by jsonSplitter and reconstructs the original JSON.
297 So jsonReconstruct(jsonSplitter(anyJson)) === anyJson
298 **/
299
300 // Sort by path length (depth) ascending
301 chunks.sort((a, b) => a.path.length - b.path.length);
302
303 let root: Record<string, any> = {};
304
305 for (let chunk of chunks) {
306 let layer = root;
307 for (let i = 0; i < chunk.path.length; i++) {
308 let key = chunk.path[i];
309 if (i === chunk.path.length - 1) {
310 layer[key] = chunk.data;
311 } else if (layer[key] === undefined) {
312 layer[key] = isNaN(Number(chunk.path[i + 1])) ? {} : [];
313 }
314 layer = layer[key];
315 }
316 }
317 return root;
318}
319
320export function chunksToProperties(chunks: Chunk[]): Properties {
321 /**

Callers 3

rebuildPropertiesFunction · 0.90
rebuildPropertiesArrayFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected