JsonEncoder class

This class converts JSON objects to strings.

Example:

const JsonEncoder encoder = JsonEncoder();
const data = {'text': 'foo', 'value': '2'};

final String jsonString = encoder.convert(data);
print(jsonString); // {"text":"foo","value":"2"}

Example of pretty-printed output:

const JsonEncoder encoder = JsonEncoder.withIndent('  ');

const data = {'text': 'foo', 'value': '2'};
final String jsonString = encoder.convert(data);
print(jsonString);
// {
//   "text": "foo",
//   "value": "2"
// }
Inheritance

Constructors

JsonEncoder([Object? toEncodable(dynamic object)?])
Creates a JSON encoder.
const
JsonEncoder.withIndent(String? indent, [Object? toEncodable(dynamic object)?])
Creates a JSON encoder that creates multi-line JSON.
const

Properties

hashCode int
The hash code for this object.
read-onlyinherited
indent String?
The string used for indention.
final
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited

Methods

bind(Stream<Object?> stream) Stream<String>
Transforms the provided stream.
override
cast<RS, RT>() Converter<RS, RT>
Provides a Converter<RS, RT> view of this stream transformer.
inherited
convert(Object? object) String
Converts object to a JSON String.
override
fuse<T>(Converter<String, T> other) Converter<Object?, T>
Fuses this with other.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
startChunkedConversion(Sink<String> sink) ChunkedConversionSink<Object?>
Starts a chunked conversion.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited