typeson library
A lightweight JSON object model with registry-based (de)serialization.
This library provides:
- Typed wrappers around JSON values (JsonString, JsonNumber, JsonBoolean, JsonArray, JsonObject).
- Extensions for ergonomic construction and pretty building.
- A pluggable JsonRegistry with JsonObjectParser strategies for custom types.
Classes
- AbstractJsonValue
- Shared implementation for JsonValue variants.
- DefaultJsonObjectParser
-
Default parser using an envelope with
__type
and__data
keys. - FlatTypeParser
- A JsonObjectParser that encodes objects using a flat structure with a configurable type discriminator key instead of the default {"__type": T, "__data": {...}} envelope.
- JsonArray
- Represents a JSON array of optional JsonValue elements.
- JsonBoolean
- Represents a JSON boolean and provides boolean operators.
- JsonBuilder
- Pretty and compact JSON string builder.
- JsonNumber
- Represents a JSON number (int or double) and provides numeric operators.
- JsonObject
- Represents a JSON object keyed by strings with optional JsonValue values.
- JsonObjectParser
- Strategy interface for encoding and decoding objects in a JsonRegistry.
- JsonRegistry
- A registry for custom object (de)serialization.
-
JsonRegistryEntry<
T> - Describes how to (de)serialize and identify a particular custom Dart type.
- JsonString
- Represents a JSON string value.
- JsonValue
- Base interface for all JSON values used by this library.
-
SimpleJsonRegistryEntry<
T> - Simple JsonRegistryEntry implementation with pluggable serializer, deserializer, optional predicate check and optional parser override.
Extensions
-
JsonArrayExtension
on List<
Object?> - Creates a JsonArray from a Dart List.
- JsonBooleanExtension on bool
- Creates a JsonBoolean from a Dart bool.
- JsonNumberExtension on num
- Creates a JsonNumber from a Dart num.
-
JsonObjectExtension
on Map<
Object?, Object?> - Creates a JsonObject from a Dart Map.
- JsonStringExtension on String
- Creates a JsonString from a Dart String.
- JsonValueExtension on JsonValue
- Convenience methods for building and working with JsonValue trees.
- RawJsonExtension on Object
- Convenience to wrap any non-null object into a raw JsonValue that preserves the underlying structure and parses lazily.
Typedefs
- JsonEntryPredicate = bool Function(Object? object)
- Predicate used by a registry entry to decide if it matches a given object.
-
JsonObjectDecoder<
T> = T Function(JsonObject json) -
Function that converts a JsonObject into an instance of
T
. -
JsonObjectEncoder<
T> = JsonObject Function(T object) -
Function that converts an instance of
T
into a JsonObject.