tryToJson function

dynamic tryToJson(
  1. dynamic object
)

Tries to convert an object to a json map by calling its toJson method if it exists.

Implementation

dynamic tryToJson(dynamic object) {
  try {
    return object?.toJson();
  } catch (_) {
    return null;
  }
}