Export JSON from Firebase Firestore

Export JSON from Firebase Firestore

Cloud Firestore data has a nested JSON-like structure, but there’s no way to export documents or collections to JSON via the Firebase Console. It’s not even possible to copy data from the web interface to the clipboard, you had to write custom scripts for these kinds of things.
That’s one of the reasons we created Firefoo, a Firebase GUI client for your desktop that can export collections and documents to JSON files among others.

How to Export Firestore Collections as JSON

1
Download and install Firefoo
2
If prompted, sign in with Google
This happens automatically if you have used the Firebase CLI on your machine
3
Right-click the collection in the sidebar and select Export Collection
default
4
Make sure the JSON Format is selected and click the Export button
default
5
Select the file destination in the file chooser.
6
That's it!
Your collection is exported to JSON and a progress popup opens. If you close that popup, the export will still continue to run in the background. Get back to the progress popup again through FileTasks.
By default, nested subcollections will be included automatically. You can prevent Firefoo from doing so by unselecting the Include Subcollections option. If you know that none of the documents contain subcollections, that’s what you should do, as it makes the export faster and saves you requests.

Format: JSON vs Newline-Separated JSON

In addition to the default JSON format, Firefoo also offers another Newline-Separated JSON format (JSONL). This JSONL format has a flat structure with a new line for every document, while the default JSON format has a nested structure.

Imagine we have two documents:
  1. A doc Germany inside a countries collection: countries/Germany
  2. A doc Berlin inside of a cities subcollection of the Germany doc:countries/Germany/cities/Berlin

JSON Format (nested)

{ "Germany": { "code": "DE", "__collections__": { "cities": { "Berlin": { "population": 3645000, "__collections__": {} } } } } }

Newline-Separated JSONL (flat)

{"__path__":"countries/Germany","code":"DE"} {"__path__":"countries/Germany/cities/Berlin","population":3645000}
This allows Firefoo to export the documents line by line. That means the export size is not limited by the working memory of your machine, making it the preferred option for large data exports or backups.

Data Types

Primitive Firestore data types are converted to the corresponding JSON types, for special Firestore types, see the following example.
{ "myString": "Firebase for the world", "myInt": 42, "myDouble": 13.37, "myBoolean": false, "myNull": null, "myArray": [21, true, "all my base"], "myMap": { "key": "value" }, "myTimestamp": { "__time__": "2021-11-23T23:13:52.000Z" }, "myGeopoint": { "__lat__": 52.52, "__lon__": 13.40 }, "myDocRef": { "__ref__": "countries/DE" }, "myBytes": { "__bytes__": "aGVsbG8gd29ybGQhCg==" }, "myInfDouble": { "__double__": "-Infinity" } "myNegInfDouble": { "__double__": "-Infinity" } "myNaNDouble": { "__double__": "NaN" } }

Export Firestore Query Results to JSON

You can export the results of a specific query with where and order-by clauses to JSON.
1
Click the collection in the sidebar on the left
2
Add Where conditions and Order by clauses. Adjust the number of documents with the Limit field, click the Run button to run your query!
3
Click the Export Results icon as seen in the screenshot below
default
4
Select the file destination in the file chooser

Export Subcollections to JSON

If you want to export a single subcollection to JSON, instead of one of the root-level collections, that’s also possible! Subcollections are not shown in the sidebar. That’s why you have to locate the subcollection in the Tree view (not the Table view) and open the right-click context menu from there. Choose Export and the same export dialog as above appears.

FAQ

How many requests will this take away from my quota?

Firefoo uses two read requests for every document that is exported. The first to fetch the data, the second to check for subcollections. If you unselect the Include Subcollections option, only one request is necessary, saving half of the total requests!

How to import the JSON Collections into Firestore?

Right-click on the target database in the sidebar and select Import Collections. In the Import Dialog, choose the JSON file and specify the target collection name in the Target Path field.