MCPcopy Index your code
hub / github.com/codeaashu/claude-code / tryFlattenJson

Function tryFlattenJson

src/tools/MCPTool/UI.tsx:298–319  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

296 * objects get one-line JSON. Returns null if content doesn't qualify.
297 */
298export function tryFlattenJson(content: string): [string, string][] | null {
299 const entries = parseJsonEntries(content, {
300 maxChars: MAX_FLAT_JSON_CHARS,
301 maxKeys: MAX_FLAT_JSON_KEYS
302 });
303 if (entries === null) return null;
304 const result: [string, string][] = [];
305 for (const [key, value] of entries) {
306 if (typeof value === 'string') {
307 result.push([key, value]);
308 } else if (value === null || typeof value === 'number' || typeof value === 'boolean') {
309 result.push([key, String(value)]);
310 } else if (typeof value === 'object') {
311 const compact = jsonStringify(value);
312 if (compact.length > 120) return null;
313 result.push([key, compact]);
314 } else {
315 return null;
316 }
317 }
318 return result;
319}
320
321/**
322 * If content is a JSON object where one key holds a dominant string payload

Callers 1

MCPTextOutputFunction · 0.85

Calls 3

parseJsonEntriesFunction · 0.85
jsonStringifyFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected