encodeJson function

String encodeJson(
  1. Object? val, {
  2. int level = 1,
  3. EncoderSettings? settings,
})

Implementation

String encodeJson(
  Object? val, {
  int level = 1,
  EncoderSettings? settings,
}) {
  // since JSONBigIntConfig.encoderSettings is not const, we can't use it as default value
  settings ??= JSONBigIntConfig.encoderSettings;

  if (val is Map) {
    return encodeMap(val, level: level, settings: settings);
  }
  if (val is List) {
    return encodeList(val, level: level, settings: settings);
  }
  if (val is String) return encodeStr(val);
  if (val is num || val is BigInt || val is bool || val == null) return '$val';
  throw ArgumentError.value(val, "Unsupported JSON type."); //Unknown type
}