MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / tryFormatJson

Function tryFormatJson

source code/components/shell/OutputLine.tsx:14–33  ·  view source on GitHub ↗
(line: string)

Source from the content-addressed store, hash-verified

12import { InVirtualListContext } from '../messageActions.js';
13import { useExpandShellOutput } from './ExpandShellOutputContext.js';
14export function tryFormatJson(line: string): string {
15 try {
16 const parsed = jsonParse(line);
17 const stringified = jsonStringify(parsed);
18
19 // Check if precision was lost during JSON round-trip
20 // This happens when large integers exceed Number.MAX_SAFE_INTEGER
21 // We normalize both strings by removing whitespace and unnecessary
22 // escapes (\/ is valid but optional in JSON) for comparison
23 const normalizedOriginal = line.replace(/\\\//g, '/').replace(/\s+/g, '');
24 const normalizedStringified = stringified.replace(/\s+/g, '');
25 if (normalizedOriginal !== normalizedStringified) {
26 // Precision loss detected - return original line unformatted
27 return line;
28 }
29 return jsonStringify(parsed, null, 2);
30 } catch {
31 return line;
32 }
33}
34const MAX_JSON_FORMAT_LENGTH = 10_000;
35export function tryJsonFormatContent(content: string): string {
36 if (content.length > MAX_JSON_FORMAT_LENGTH) {

Callers

nothing calls this directly

Calls 2

jsonParseFunction · 0.85
jsonStringifyFunction · 0.85

Tested by

no test coverage detected