MCPcopy Index your code
hub / github.com/modelcontextprotocol/inspector / tryParseJson

Function tryParseJson

client/src/utils/jsonUtils.ts:89–106  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

87 * @returns Object with success boolean and either parsed data or original string
88 */
89export function tryParseJson(str: string): {
90 success: boolean;
91 data: JsonValue;
92} {
93 const trimmed = str?.trim();
94 if (
95 trimmed &&
96 !(trimmed.startsWith("{") && trimmed.endsWith("}")) &&
97 !(trimmed.startsWith("[") && trimmed.endsWith("]"))
98 ) {
99 return { success: false, data: str };
100 }
101 try {
102 return { success: true, data: JSON.parse(str) };
103 } catch {
104 return { success: false, data: str };
105 }
106}
107
108/**
109 * Updates a value at a specific path in a nested JSON structure

Callers 2

JsonView.tsxFile · 0.90
jsonUtils.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…