encode static method

String encode(
  1. Object? object, {
  2. bool formatted = false,
  3. bool encodeForProtocol = false,
})

Encode the provided object to a Json-formatted String. If formatted is true, the output will be formatted with two spaces indentation.

Implementation

static String encode(
  Object? object, {
  bool formatted = false,
  bool encodeForProtocol = false,
}) {
  final encoder = JsonEncoder.withIndent(
    formatted ? '  ' : null,
    encodeForProtocol ? toEncodableForProtocol : toEncodable,
  );
  return encoder.convert(object);
}