JsonModule
PackageReified.Schema
Functions for compiling and running JSON codecs over built model schemas.
Summary
| Name | Signature | Synopsis |
|---|---|---|
| Operations | ||
| compile | Json.compile schema | Compiles a completed schema into a reusable JSON codec. |
| serialize | Json.serialize codec value | Serializes a trusted model to a JSON string through a compiled codec. |
| serializeBytes | Json.serializeBytes codec value | Serializes a trusted model to UTF-8 JSON bytes through a compiled codec. |
| defaults | Json.defaults | The unmodified JSON writer options: compact, minimal escaping — exactly what , serializeBytes, and serializeToStream produce. |
| indented | Json.indented options | Configures the writer to indent nested levels by two spaces. |
| serializeWith | Json.serializeWith configure codec value | Serializes a trusted model to a JSON string, configuring the writer through . |
| serializeBytesWith | Json.serializeBytesWith configure codec value | Serializes a trusted model to UTF-8 JSON bytes, configuring the writer through . |
| serializeIndented | Json.serializeIndented codec value | Serializes a trusted model to an indented JSON string with two-space nesting. |
| reindent | Json.reindent json | Reformats a JSON string with two-space indentation. |
| parseData | Json.parseData json | Parses one JSON value into source-neutral structured data. |
| deserializeBytes | Json.deserializeBytes codec bytes | Deserializes UTF-8 JSON bytes to a trusted model through a compiled codec. |
| deserialize | Json.deserialize codec json | Deserializes a JSON string to a trusted model through a compiled codec. |
| tryDeserialize | Json.tryDeserialize codec json | Deserializes a JSON string, returning decode failures as a rendered message instead of raising. |
| serializeToStream | Json.serializeToStream codec stream value | Serializes a trusted model as UTF-8 JSON directly to a stream through a compiled codec, flushing once when complete. |
| serializeToStreamWith | Json.serializeToStreamWith configure codec stream value | Serializes a trusted model as UTF-8 JSON directly to a stream, configuring the writer through . |
| deserializeStreamAsync | Json.deserializeStreamAsync codec stream | Reads a stream to end into a pooled buffer, then deserializes it as UTF-8 JSON through a compiled codec. |
Operations
kind:member
Compiles a completed schema into a reusable JSON codec.
Parameters
| Name | Type | Description |
|---|---|---|
| schema | Schema<'model> |
Returns
JsonCodec<'model>
Verification Examples
open Reified.SchemaDSL
open Reified.ConstraintDSL
type Customer = { Name: string; Email: string }
let customerSchema =
schema<Customer> {
field _.Name { constrain present }
field _.Email { constraints [ present; email ] }
construct (fun name email -> { Name = name; Email = email })
}
let customer = { Name = "Ada"; Email = "ada@example.org" }
let codec = Json.compile customerSchema
let json = Json.serialize codec customer
let roundTripped = Json.deserialize codec jsonkind:member
kind:member
kind:member
kind:member
kind:member
Serializes a trusted model to a JSON string, configuring the writer through
JsonWriteOptions.
Parameters
| Name | Type | Description |
|---|---|---|
| configure | JsonWriteOptions -> JsonWriteOptions | |
| codec | JsonCodec<'model> | |
| value | 'model |
Returns
string
kind:member
Serializes a trusted model to UTF-8 JSON bytes, configuring the writer through
JsonWriteOptions.
Parameters
| Name | Type | Description |
|---|---|---|
| configure | JsonWriteOptions -> JsonWriteOptions | |
| codec | JsonCodec<'model> | |
| value | 'model |
Returns
byte[]
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
Serializes a trusted model as UTF-8 JSON directly to a stream, configuring the writer through
JsonWriteOptions. Not available on Fable.
Parameters
| Name | Type | Description |
|---|---|---|
| configure | JsonWriteOptions -> JsonWriteOptions | |
| codec | JsonCodec<'model> | |
| stream | Stream | |
| value | 'model |
Returns
unit