Json
JSON utilities with Effect Schema integration.
Provides type-safe JSON operations including type guards, parsing, encoding, and validation using Effect Schema. Supports JSON primitives, objects, and recursive value structures with comprehensive error handling.
Import
import { Json } from '@wollybeard/kit'
import * as Json from '@wollybeard/kit/json'
Codec
[C]
codec
Codec<Value>
Codec for JSON values with pretty-printing. Uses Effect's parseJson for decoding.
[C]
encode
Encode<Value>
Encode a JSON value to a pretty-printed string.
[C]
decode
Decode<Value>
Parse a JSON string to a typed value. Uses Effect's parseJson for better error messages.
Schemas
[C]
Primitive
{
parse: ;
;((value: unknown) => string | number | boolean | null)
}
Exported schemas for parsing JSON types. These are used in tests and provide parse methods.
[C]
Value
{
parse: ;
;((value: unknown) => Value)
}
[C]
PrimitiveSchema
Union<[typeof String, typeof Number, typeof Boolean, typeof Null]>
JSON primitive value schema. Matches: string, number, boolean, or null.
[C]
ValueSchema
Schema<Value, Value, never>
JSON value schema. Matches any valid JSON value: primitives, objects, or arrays (recursively).
[C]
ObjectSchema
Record$<typeof String, Schema<Value, Value, never>>
JSON object schema. Matches objects with string keys and JSON values.
[C]
parseJsonSchema
SchemaClass<unknown, string, never>
Schema for parsing JSON strings to unknown values. Uses Effect's parseJson for better error handling.
[F]
parseJsonAs
<A>(schema: Schema<A, A, never>): transform<SchemaClass<unknown, string, never>, Schema<A, A, never>>
Schema for parsing JSON with type validation.
[C]
ObjectParser
{ parse: (value: unknown) => { readonly[x: string]: Value; }; }
Type Guards
[F]
isPrimitive
(value: unknown): boolean
Type guard to check if a value is a JSON primitive.
[F]
isValue
(value: unknown): boolean
Type guard to check if a value is a valid JSON value.
[F]
isObject
(value: unknown): boolean
Type guard to check if a value is a JSON object.
Types
[U]
Primitive
type Primitive = string | number | boolean | null
JSON primitive type. Matches: string, number, boolean, or null.
[T]
Obj
type Obj = { [key in string]?: Value }
JSON object type.
[U]
Value
type Value = Primitive | Obj | Value[]
JSON value type. Matches any valid JSON value: primitives, objects, or arrays (recursively).
[T]
Object
type Obj = { [key in string]?: Value }
JSON object type.