parseJson
constparseJson: {<S>(schema,options?):transform<SchemaClass<unknown,string,never>,S>; (options?):SchemaClass<unknown,string>; }
Defined in: node_modules/.pnpm/effect@3.15.2/node_modules/effect/dist/dts/Schema.d.ts:2569
The ParseJson combinator provides a method to convert JSON strings into the unknown type using the underlying
functionality of JSON.parse. It also utilizes JSON.stringify for encoding.
You can optionally provide a ParseJsonOptions to configure both JSON.parse and JSON.stringify executions.
Optionally, you can pass a schema Schema<A, I, R> to obtain an A type instead of unknown.
Call Signature
Section titled “Call Signature”<
S>(schema,options?):transform<SchemaClass<unknown,string,never>,S>
The ParseJson combinator provides a method to convert JSON strings into the unknown type using the underlying
functionality of JSON.parse. It also utilizes JSON.stringify for encoding.
You can optionally provide a ParseJsonOptions to configure both JSON.parse and JSON.stringify executions.
Optionally, you can pass a schema Schema<A, I, R> to obtain an A type instead of unknown.
Type Parameters
Section titled “Type Parameters”S extends Any
Parameters
Section titled “Parameters”schema
Section titled “schema”S
options?
Section titled “options?”Returns
Section titled “Returns”transform<SchemaClass<unknown, string, never>, S>
Example
Section titled “Example”import * as assert from "node:assert"import * as Schema from "effect/Schema"
assert.deepStrictEqual(Schema.decodeUnknownSync(Schema.parseJson())(`{"a":"1"}`), { a: "1" })assert.deepStrictEqual(Schema.decodeUnknownSync(Schema.parseJson(Schema.Struct({ a: Schema.NumberFromString })))(`{"a":"1"}`), { a: 1 })3.10.0
Call Signature
Section titled “Call Signature”(
options?):SchemaClass<unknown,string>
The ParseJson combinator provides a method to convert JSON strings into the unknown type using the underlying
functionality of JSON.parse. It also utilizes JSON.stringify for encoding.
You can optionally provide a ParseJsonOptions to configure both JSON.parse and JSON.stringify executions.
Optionally, you can pass a schema Schema<A, I, R> to obtain an A type instead of unknown.
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”SchemaClass<unknown, string>
Example
Section titled “Example”import * as assert from "node:assert"import * as Schema from "effect/Schema"
assert.deepStrictEqual(Schema.decodeUnknownSync(Schema.parseJson())(`{"a":"1"}`), { a: "1" })assert.deepStrictEqual(Schema.decodeUnknownSync(Schema.parseJson(Schema.Struct({ a: Schema.NumberFromString })))(`{"a":"1"}`), { a: 1 })3.10.0
Example
Section titled “Example”import * as assert from "node:assert"import * as Schema from "effect/Schema"
assert.deepStrictEqual(Schema.decodeUnknownSync(Schema.parseJson())(`{"a":"1"}`), { a: "1" })assert.deepStrictEqual(Schema.decodeUnknownSync(Schema.parseJson(Schema.Struct({ a: Schema.NumberFromString })))(`{"a":"1"}`), { a: 1 })3.10.0