| 1085 | * @since 4.0.0 |
| 1086 | */ |
| 1087 | export function stringifyJson(options?: StringifyJsonOptions): Getter<string, unknown> { |
| 1088 | return onSome((input, parseOptions) => |
| 1089 | Effect.try({ |
| 1090 | try: () => { |
| 1091 | const output = JSON.stringify(input, options?.replacer as any, options?.space) |
| 1092 | if (output === undefined) { |
| 1093 | throw new TypeError("Value cannot be represented as JSON") |
| 1094 | } |
| 1095 | return Option.some(output) |
| 1096 | }, |
| 1097 | catch: () => |
| 1098 | new SchemaIssue.InvalidValue( |
| 1099 | { expected: "a JSON-serializable value" }, |
| 1100 | input, |
| 1101 | parseOptions |
| 1102 | ) |
| 1103 | }) |
| 1104 | ) |
| 1105 | } |
| 1106 | |
| 1107 | /** |
| 1108 | * Parses a string into a record of key-value pairs. |