(content: string)
| 78 | } |
| 79 | |
| 80 | function parseJSONLContent(content: string): FileParseResult { |
| 81 | const lines = content.split('\n').filter((line) => line.trim()) |
| 82 | const items: unknown[] = [] |
| 83 | |
| 84 | for (const line of lines) { |
| 85 | try { |
| 86 | items.push(JSON.parse(line)) |
| 87 | } catch { |
| 88 | throw new Error(`Invalid JSONL: failed to parse line: ${line.slice(0, 100)}`) |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | const formattedContent = JSON.stringify(items, null, 2) |
| 93 | |
| 94 | return { |
| 95 | content: formattedContent, |
| 96 | metadata: { |
| 97 | type: 'json', |
| 98 | isArray: true, |
| 99 | keys: [], |
| 100 | itemCount: items.length, |
| 101 | depth: items.length > 0 ? 1 + getJsonDepth(items[0]) : 1, |
| 102 | }, |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Calculate the depth of a JSON object |
no test coverage detected