(options?: ParseJsonOptions)
| 4801 | const getErrorMessage = (e: unknown): string => e instanceof Error ? e.message : String(e) |
| 4802 | |
| 4803 | const 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 |
no test coverage detected