toJson property

dynamic toJson

Attempts to decode the string as a JSON object. Returns null if decoding fails.

Example:

print('{"key": "value"}'.toJson); // Output: {key: value}
print('abc'.toJson); // Output: null

Implementation

dynamic get toJson {
  try {
    return json.decode(this);
  } catch (e) {
    return null;
  }
}