toJson method
Returns a JSON-serializable representation of this snapshot, which DocumentSnapshot.fromJson reads back and
FirebaseFirestore.documentSnapshotsFromJson listens from.
The bundle field holds the document as a Firestore bundle (empty when the document does not exist). Throws a
FirestoreException (failed-precondition) if the snapshot has pending writes: await waitForPendingWrites() first.
This is the JS SDK DocumentSnapshot.toJSON(); the JSON is interchangeable with the one of the JS SDK (Node).
One difference: for a document that does not exist the bundle is empty, which this SDK reads back as a missing
document and the JS SDK cannot read.
final Map<String, Object?> json = (await firestore.doc('cities/SF').get())
.toJson();
// Later, possibly in another program:
final DocumentSnapshot<Map<String, Object?>> restored =
DocumentSnapshot<Map<String, Object?>>.fromJson(firestore, json);
print(restored.data());
Implementation
Map<String, Object?> toJson() => snapshot_json.documentSnapshotToJson(
_firestore,
_key,
document,
hasPendingWrites: metadata.hasPendingWrites,
);