toJsonString method

String toJsonString({
  1. bool pretty = false,
})

Converts this snapshot to a JSON string.

Parameters:

  • pretty: If true, the JSON will be pretty-printed with indentation. Defaults to false for 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);
  }
}