Import JSON into Firebase Firestore

Import JSON into Firebase Firestore

Cloud Firestore, the NoSQL Database of the Google Cloud Computing world, makes some things harder than they should be! One of them is importing your data. There’s no way to import collections or documents using the Firebase Console. Previously you had to write a custom script that parsed the JSON file, iterated over the rows and created Firestore documents.

Upload JSON as Firestore Collection

Download and install Firefoo
Right-click your project in the sidebar and choose Import Collections
Click on the Data File field and select your JSON file
Enter the collection name into the Target Path field
That's it! Click the Import button!
Your data is imported into Firestore and a progress popup opens. The import will continue to run in the background when you close that popup. Get back to the progress popup again through FileTasks.

Supported JSON formats

Firefoo has support for three different JSON input formats

JSON Array of documents

A JSON file with an array of objects at the root level.
[ { "name": "Max Musterman", "age": 23 }, { "name": "Kevin Schmidt", "age": 42 } ]

2. JSON Object with documents as values

A JSON file with an object at the root level. Every value inside that object needs to be an object itself, containing data for one document each.
{ "max": { "name": "Max Musterman", "age": 23 }, "kevin": { "name": "Kevin Schmidt", "age": 42 } }

3. Newline-delimited JSON with one document per line

Note that there are no commas between the lines, instead the JSON documents are separated by line breaks. The whole file is not valid JSON, but every line is a valid JSON object.
{"name": "Max Musterman", "age": 23} {"name": "Kevin Schmidt", "age": 42}

Document IDs

When auto-generate is selected, Firefoo will generate random 20-character strings (e.g.oXm520lZ3SAjDOWPW7Z1) as document IDs. Select Use field to use the values of a field as document IDs. That field can also be nested in a JSON Object, it will appear with dot notation in the dropdown menu. Make sure that the data contains unique values for every document, otherwise documents with the same ID value will get overwritten. These values must follow the constraints on document IDs, most notably they must not contain slashes.
When importing JSON in the 2. JSON Object with documents as values formats (see above), there’s another option Use keys, which will use the top-level keys as document IDs. In this example the document IDs are max and kevin.

Data Types

Strings, Booleans, Arrays, Maps, and null values from the JSON are converted to the corresponding Firestore types. Numbers are imported as a Firestore Integer if they are actually Integers, otherwise they become Doubles. Be careful: This means the same field could be an Integer in one doc but a Double in another doc!
Firefoo does not attempt to parse Timestamps, Geopoints and Document References from string values. Instead, there’s a special syntax you can use in your JSON file:
{ "myTimestamp": { "__time__": "2021-11-23T23:13:52.000Z" }, "myGeopoint": { "__lat__": 52.52, "__lon__": 13.40 }, "myDocRef": { "__ref__": "countries/DE" }, }


Import JSON data into an existing Firestore collection

Instead of creating a new collection from the JSON data, it’s also possible to add the data into an existing collection. Right-click on the collection in the sidebar to do so and selectImport from there.
Make sure to adjust the Field Names in the field mapping table so that they match the structure of the existing documents in the collection. When you choose to use document IDs from a CSV column, and there‘s already a document existing with the same ID, the data will be merged with imported fields overwriting existing fields.

Import JSON into a subcollection

To import the data from the CSV file as a subcollection into a document, specify the path to that subcollection in the Target Path field, e.g. /myCollection/myDocId/mySubcollection. This works for existing subcollections as well as creating new subcollections.

How many requests will this take away from my quota?

Firefoo uses exactly one write request for every document that is uploaded to your Firestore database.