MCPcopy Create free account
hub / github.com/arktypeio/arktype / stringifyJson

Function stringifyJson

ark/type/keywords/functions.ts:315–328  ·  view source on GitHub ↗
(
	data: Json,
	ctx?: Traversal
)

Source from the content-addressed store, hash-verified

313)
314
315export const stringifyJson = (
316 data: Json,
317 ctx?: Traversal
318): string | ArkError => {
319 try {
320 const result = JSON.stringify(data)
321 if (result !== undefined) return result
322 if (!ctx) throw new TypeError("Value is not JSON-serializable")
323 return ctx.error(jsonStringifyError)
324 } catch (e) {
325 if (!ctx || !(e instanceof TypeError)) throw e
326 return ctx.error({ ...jsonStringifyError, cause: e })
327 }
328}
329
330// inverses of parse keywords, which arktype/codecs encodes with
331export const writeIsoDate = (date: Date): string => {

Callers

nothing calls this directly

Calls 1

errorMethod · 0.45

Tested by

no test coverage detected