tryEncodeJson static method
BuBytes?
tryEncodeJson(
- Object? json, {
- String? indent,
- bool toStringEncodable = false,
- Object? toEncodable(
- dynamic
- JsonEncodeOptions? options,
Attempts to encode a JSON-serializable json object into a list of bytes,
returning null if the conversion to JSON string fails.
Implementation
static BuBytes? tryEncodeJson(
Object? json, {
String? indent,
bool toStringEncodable = false,
Object? Function(dynamic)? toEncodable,
JsonEncodeOptions? options,
}) {
if (json == null) return null;
try {
return encodeJson(
json,
indent: indent,
toEncodable: toEncodable,
toStringEncodable: toStringEncodable,
options: options,
);
} catch (_) {
return null;
}
}