toJsonString method
Converts this snapshot to a JSON string.
Parameters:
pretty: Iftrue, the JSON will be pretty-printed with indentation. Defaults tofalsefor compact output.
Returns: A JSON string representation of this snapshot.
Example:
final jsonString = snapshot.toJsonString();
// Or with pretty printing:
final prettyJson = snapshot.toJsonString(pretty: true);
Implementation
String toJsonString({bool pretty = false}) {
final json = toJson();
if (pretty) {
const encoder = JsonEncoder.withIndent(' ');
return encoder.convert(json);
} else {
return jsonEncode(json);
}
}