MCPcopy
hub / github.com/simstudioai/sim / tryParseJson

Function tryParseJson

apps/sim/lib/workflows/subblocks/display.ts:166–180  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

164 * original value if parsing fails.
165 */
166const tryParseJson = (value: unknown): unknown => {
167 if (typeof value !== 'string') return value
168 try {
169 const trimmed = value.trim()
170 if (
171 (trimmed.startsWith('[') && trimmed.endsWith(']')) ||
172 (trimmed.startsWith('{') && trimmed.endsWith('}'))
173 ) {
174 return JSON.parse(trimmed)
175 }
176 } catch {
177 return value
178 }
179 return value
180}
181
182/**
183 * Formats a subblock value for display, intelligently handling nested

Callers 2

getDisplayValueFunction · 0.70
resolveFilterFieldLabelFunction · 0.70

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected