MCPcopy Index your code
hub / github.com/Effect-TS/effect / getParseJsonTransformation

Function getParseJsonTransformation

packages/effect/src/Schema.ts:4803–4823  ·  view source on GitHub ↗
(options?: ParseJsonOptions)

Source from the content-addressed store, hash-verified

4801const getErrorMessage = (e: unknown): string => e instanceof Error ? e.message : String(e)
4802
4803const getParseJsonTransformation = (options?: ParseJsonOptions): SchemaClass<unknown, string> =>
4804 transformOrFail(
4805 String$.annotations({ description: "a string to be decoded into JSON" }),
4806 Unknown,
4807 {
4808 strict: true,
4809 decode: (i, _, ast) =>
4810 ParseResult.try({
4811 try: () => JSON.parse(i, options?.reviver),
4812 catch: (e) => new ParseResult.Type(ast, i, getErrorMessage(e))
4813 }),
4814 encode: (a, _, ast) =>
4815 ParseResult.try({
4816 try: () => JSON.stringify(a, options?.replacer, options?.space),
4817 catch: (e) => new ParseResult.Type(ast, a, getErrorMessage(e))
4818 })
4819 }
4820 ).annotations({
4821 title: "parseJson",
4822 schemaId: AST.ParseJsonSchemaId
4823 })
4824
4825/**
4826 * The `ParseJson` combinator provides a method to convert JSON strings into the `unknown` type using the underlying

Callers 1

parseJsonFunction · 0.85

Calls 4

transformOrFailInterface · 0.85
parseMethod · 0.80
getErrorMessageFunction · 0.70
annotationsMethod · 0.65

Tested by

no test coverage detected