MCPcopy Index your code
hub / github.com/simstudioai/sim / getJsonDepth

Function getJsonDepth

apps/sim/lib/file-parsers/json-parser.ts:109–118  ·  view source on GitHub ↗

* Calculate the depth of a JSON object

(obj: any)

Source from the content-addressed store, hash-verified

107 * Calculate the depth of a JSON object
108 */
109function getJsonDepth(obj: any): number {
110 if (obj === null || typeof obj !== 'object') return 0
111
112 if (Array.isArray(obj)) {
113 return obj.length > 0 ? 1 + Math.max(...obj.map(getJsonDepth)) : 1
114 }
115
116 const depths = Object.values(obj).map(getJsonDepth)
117 return depths.length > 0 ? 1 + Math.max(...depths) : 1
118}

Callers 3

parseJSONFunction · 0.85
parseJSONBufferFunction · 0.85
parseJSONLContentFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected