Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { Data, Effect, Schema } from 'effect'; |
| 2 | |
| 3 | export class JSONParseError extends Data.TaggedError('effects/JSONParseError')<{ |
| 4 | readonly cause: unknown; |
| 5 | readonly message: string; |
| 6 | }> {} |
| 7 | |
| 8 | /** |
| 9 | * The canonical "JSON object" schema: a string-keyed record of unknown values. |
| 10 | * Import this instead of re-declaring `Schema.Record({ key: Schema.String, |
| 11 | * value: Schema.Unknown })` locally. |
| 12 | */ |
| 13 | export const JsonRecordSchema = Schema.Record(Schema.String, Schema.Unknown); |
| 14 | |
| 15 | export const JSONParse = (s: string) => |
| 16 | Schema.decodeUnknownEffect(Schema.fromJsonString(JsonRecordSchema))(s).pipe( |
| 17 | Effect.mapError(cause => new JSONParseError({ cause, message: 'Failed to parse JSON' })) |
| 18 | ); |