MCPcopy
hub / github.com/arktypeio/arktype / parseJson

Function parseJson

ark/type/keywords/string.ts:464–481  ·  view source on GitHub ↗
(s: string, ctx: Traversal)

Source from the content-addressed store, hash-verified

462})
463
464const parseJson: Morph<string> = (s: string, ctx: Traversal) => {
465 if (s.length === 0) {
466 return ctx.error({
467 code: "predicate",
468 expected: jsonStringDescription,
469 actual: "empty"
470 })
471 }
472 try {
473 return JSON.parse(s)
474 } catch (e) {
475 return ctx.error({
476 code: "predicate",
477 expected: jsonStringDescription,
478 problem: writeJsonSyntaxErrorProblem(e)
479 })
480 }
481}
482
483export const json: stringJson.module = Scope.module(
484 {

Callers 1

json.test.tsFile · 0.85

Calls 2

errorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…