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

Function parseJSON

apps/sim/lib/file-parsers/json-parser.ts:7–34  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

5 * Parse JSON files
6 */
7export async function parseJSON(filePath: string): Promise<FileParseResult> {
8 const fs = await import('fs/promises')
9 const content = await fs.readFile(filePath, 'utf-8')
10
11 try {
12 // Parse to validate JSON
13 const jsonData = JSON.parse(content)
14
15 // Return pretty-printed JSON for better readability
16 const formattedContent = JSON.stringify(jsonData, null, 2)
17
18 // Extract metadata about the JSON structure
19 const metadata = {
20 type: 'json',
21 isArray: Array.isArray(jsonData),
22 keys: Array.isArray(jsonData) ? [] : Object.keys(jsonData),
23 itemCount: Array.isArray(jsonData) ? jsonData.length : undefined,
24 depth: getJsonDepth(jsonData),
25 }
26
27 return {
28 content: formattedContent,
29 metadata,
30 }
31 } catch (error) {
32 throw new Error(`Invalid JSON: ${getErrorMessage(error, 'Unknown error')}`)
33 }
34}
35
36/**
37 * Parse JSON from buffer

Callers

nothing calls this directly

Calls 4

getErrorMessageFunction · 0.90
getJsonDepthFunction · 0.85
readFileMethod · 0.80
parseMethod · 0.80

Tested by

no test coverage detected