MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / tryParseEmbeddedJSON

Function tryParseEmbeddedJSON

internal/mcp/dispatch.go:271–284  ·  view source on GitHub ↗

tryParseEmbeddedJSON attempts to parse s as JSON, returning the native value when it succeeds. Returns (nil, false) when the string is empty, doesn't start with `{` or `[`, or fails to unmarshal — leaves the caller free to keep the original string. We require the leading-brace check before attempti

(s string)

Source from the content-addressed store, hash-verified

269// quoted-but-bare strings don't get spuriously coerced into Go
270// values agents weren't expecting.
271func tryParseEmbeddedJSON(s string) (any, bool) {
272 s = strings.TrimSpace(s)
273 if s == "" {
274 return nil, false
275 }
276 if !strings.HasPrefix(s, "{") && !strings.HasPrefix(s, "[") {
277 return nil, false
278 }
279 var out any
280 if err := json.Unmarshal([]byte(s), &out); err != nil {
281 return nil, false
282 }
283 return out, true
284}
285
286// ListWorkspaces satisfies WorkspaceLister so error helpers can
287// populate available_workspaces hints. Best-effort: if listing fails

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected