jsontool library
A collection of JSON related operations.
JSON is a text format which can represent a general "JSON structure". There are many ways to generate JSON text and convert JSON text to native data structures in most languages.
A JSON structure is either a primitive value: a number, a string, a boolean or a null value, or it is a composite value. The composite value is either a JSON array, a seqeunce of JSON structures, or a JSON object, a sequence of pairs of string keys and JSON structure values.
Dart typically represents the JSON structure using List and Map objects for the composite values and num, String, bool and Null values for the primitive values.
This package provides various ways to operate on a JSON structure without necessarily creating intermediate Dart lists or maps.
The JsonReader provides a pull based approach to investigating and deconstructing a JSON structure, whether it's represented as a string, bytes which are the UTF-8 encoding of such a string, or by Dart object structures.
The JsonSink provides a push based approach to building a JSON structure. This can be used to create JSON source or structures from other kinds of values.
The JsonBuilder functions provide a composable way to convert a JSON structure to another kind of value.
Classes
-
JsonProcessor<
Reader extends JsonReader> - A generalized JSON processor.
-
JsonReader<
SourceSlice> - A JSON reader which provides pull-based access to individual JSON tokens.
- JsonSink
- A generalized JSON visitor interface.
-
JsonSinkProcessor<
Reader extends JsonReader, Sink extends JsonSink> - A generalized JSON processor which forwards data to a JSON sink.
-
JsonWriter<
T> - A JSON sink which emits JSON source or JSON-like structures.
- StringSlice
- A slice of a larger string.
Constants
- nullJsonSink → const JsonSink
- A JsonSink which accepts any calls and ignores them.
Functions
-
jsonArray<
T> (JsonBuilder< T> elementBuilder) → JsonBuilder<List< T> > - Reads an array of values from a JsonReader.
-
jsonBool(
JsonReader reader) → bool -
Reads a boolean from
reader
. -
jsonByteWriter(
Sink< List< sink, {Encoding encoding = utf8, bool? asciiOnly}) → JsonWriter<int> >List< int> > - Creates a JsonSink which builds a byte representation of the JSON structure.
-
jsonDateString(
JsonReader reader) → DateTime -
Builds a DateTime from a JSON string read from
reader
. -
jsonDouble(
JsonReader reader) → double -
Reads a double from
reader
. -
jsonFoldArray<
T, E> (JsonBuilder< E> elementBuilder, T initialValue(), T combine(T previus, E elementValue)) → JsonBuilder<T> - Builds a value from a JSON array.
-
jsonFoldObject<
T, E> (JsonBuilder< E> elementBuilder, T initialValue(), T combine(T previus, String? key, E elementValue)) → JsonBuilder<T> - Reads a JSON object and combines its entries into a single value.
-
jsonIndexedArray<
T> (JsonBuilder< T> elementBuilder(int index)) → JsonBuilder<List< T> > - Reads an array of values from JsonReader.
-
jsonInt(
JsonReader reader) → int -
Reads an integer from
reader
. -
jsonNum(
JsonReader reader) → num -
Reads a number from
reader
. -
jsonObject<
T> (JsonBuilder< T> valueBuilder) → JsonBuilder<Map< String?, T> > - Builds a map from a JSON object.
-
jsonObjectWriter(
void result(Object?)) → JsonWriter< Object?> - Creates a JsonSink which builds a Dart JSON object structure.
-
jsonOptional<
T> (JsonBuilder< T> builder) → JsonBuilder<T?> -
Reads eiher a
null
or whatbuilder
reads from a JsonReader. -
jsonString(
JsonReader reader) → String -
Reads a string from
reader
. -
jsonStringWriter(
StringSink sink, {String? indent, bool asciiOnly = false}) → JsonWriter< String> - Creates a JsonSink which builds a JSON string.
-
jsonStruct<
T> (Map< String, JsonBuilder< valueBuilders, [JsonBuilder<T> >T> ? defaultBuilder]) → JsonBuilder<Map< String?, T> > - Builds a map from a JSON object
-
jsonUriString(
JsonReader reader) → Uri -
Builds a Uri from a JSON string read from
reader
. -
jsonValue(
JsonReader reader) → Object? -
Parses a JSON value from
reader
into a plain JSON-like structure. -
validateJsonReader<
T> (JsonReader< T> reader) → JsonReader<T> - Makes a JsonReader validate the order of its operations.
-
validateJsonSink(
JsonSink sink, {bool allowReuse = false}) → JsonSink - Wraps a JsonSink in a validating layer.
Typedefs
-
JsonBuilder<
T> = T Function(JsonReader) - A function reading JSON data from a JsonReader into a Dart value.