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

Function parseJSONBuffer

apps/sim/lib/file-parsers/json-parser.ts:39–61  ·  view source on GitHub ↗
(buffer: Buffer)

Source from the content-addressed store, hash-verified

37 * Parse JSON from buffer
38 */
39export async function parseJSONBuffer(buffer: Buffer): Promise<FileParseResult> {
40 const content = buffer.toString('utf-8')
41
42 try {
43 const jsonData = JSON.parse(content)
44 const formattedContent = JSON.stringify(jsonData, null, 2)
45
46 const metadata = {
47 type: 'json',
48 isArray: Array.isArray(jsonData),
49 keys: Array.isArray(jsonData) ? [] : Object.keys(jsonData),
50 itemCount: Array.isArray(jsonData) ? jsonData.length : undefined,
51 depth: getJsonDepth(jsonData),
52 }
53
54 return {
55 content: formattedContent,
56 metadata,
57 }
58 } catch (error) {
59 throw new Error(`Invalid JSON: ${getErrorMessage(error, 'Unknown error')}`)
60 }
61}
62
63/**
64 * Parse JSONL (JSON Lines) files — one JSON object per line

Callers

nothing calls this directly

Calls 4

getErrorMessageFunction · 0.90
getJsonDepthFunction · 0.85
parseMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected