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.
Download and install Firefoo
If prompted, sign in with Google
This happens automatically if you have used the Firebase CLI on your machine
Right-click the collection in the sidebar and select Export Collection
Make sure the JSON Format is selected and click the Export button
Select the file destination in the file chooser.
That's it!
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.
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:
Imagine we have two documents:
- A doc Germany inside a countries collection:
countries/Germany
- A doc Berlin inside of a cities subcollection of the Germany doc:
countries/Germany/cities/Berlin
{
"Germany": {
"code": "DE",
"__collections__": {
"cities": {
"Berlin": {
"population": 3645000,
"__collections__": {}
}
}
}
}
}
{"__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.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" }
}
You can export the results of a specific query with where and order-by clauses to JSON.
Click the collection in the sidebar on the left
Add Where conditions and Order by clauses. Adjust the number of documents with the Limit field, click the Run button to run your query!
Click the Export Results icon as seen in the screenshot below
Select the file destination in the file chooser
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.
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!
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.