CSV to JSON for MongoDB
Loading CSV data into MongoDB the right way means producing a JSON array of documents that mongoimport accepts with the --jsonArray flag, with values typed correctly so numeric fields are real numbers and boolean fields are real booleans rather than strings.
Native JSON tool
CSV to JSON
mongoimport-ready array
Auto-typed values
Nested sub-documents
No data upload
- Cost
- Free tier
- Sign-up
- Not required
- Processing
- Tool-specific
- Privacy
- Clearly disclosed
Add this CSV to JSON to your website
Drop the CSV to JSON into a blog post, product docs, intranet, or school portal with one iframe. Processing, privacy, and usage limits are the same as on the full tool page.
- One copy-ready line of HTML
- Responsive — adapts to any container width
- No API credentials are placed in the snippet
Embed code
<iframe
src="https://www.fixtools.io/json/csv-to-json?embed=1"
width="100%"
height="780"
frameborder="0"
style="border:0;border-radius:16px;max-width:900px;"
title="CSV to JSON by FixTools"
loading="lazy"
allow="clipboard-write"
></iframe>Attribution-friendly: a small "Powered by FixTools" link appears in the embed footer.
Producing JSON that mongoimport actually accepts
mongoimport accepts JSON in two forms: a single document per line (JSONL) or a JSON array passed with --jsonArray. The array form is more convenient for files you have generated from another source because you can inspect the array as a whole, validate the syntax with standard JSON tools, and load it in a single command. FixTools produces the array form by default, so the conversion output drops straight into mongoimport --jsonArray --collection mycoll --file converted.json with no intermediate transformation.
Typing matters in MongoDB because BSON has distinct types for integers, doubles, and strings. Storing a price field as "12.99" rather than 12.99 means range queries do not work as expected and aggregation pipelines have to coerce on every operation. Type inference at conversion time emits real numbers for numeric columns, which BSON encodes as either Int32 or Double depending on whether decimal points appear. Boolean fields become real booleans which support direct boolean queries.
Sub-documents are the natural MongoDB way to represent nested structure, and dot-notation in your CSV headers maps directly to BSON sub-documents through the standard MongoDB dot-notation convention. A header address.city becomes documents like { address: { city: ... } } in the array, which then loads as BSON sub-documents. The same notation works for arrays inside documents using bracket-index syntax, producing tags arrays and arrays of line items where appropriate.
ObjectId, ISODate, and other extended BSON types are not auto-generated by the converter because they require either MongoDB Extended JSON syntax or post-load processing. If your data should have an _id field of ObjectId type, leave it out of the CSV and let MongoDB generate ObjectIds on insert. For dates, store ISO 8601 strings in the CSV and let an aggregation pipeline convert them to BSON dates after load with $toDate. This keeps the converter focused on portable JSON rather than locking the output to MongoDB-specific syntax.
How to use this tool
Array of documents, typed values, sub-documents via dot notation. Ready for mongoimport --jsonArray.
How It Works
Step-by-step guide to csv to json for mongodb:
- 1
Design your document shape
Decide on field names and which fields should be nested. Use dot-notation in CSV headers for nested fields. Leave _id out unless you have specific ObjectId values to preserve.
- 2
Prepare and convert CSV
Paste the CSV into FixTools with type inference enabled. Inspect the preview to confirm numeric fields are numbers and nested structures look right.
- 3
Download the array
Save the JSON as a file. Use a descriptive name like users.json that matches the target collection.
- 4
Run mongoimport
Use mongoimport --uri mongodb://localhost:27017/mydb --collection users --file users.json --jsonArray. Confirm successful import with mongosh and a quick db.users.find().count().
- 5
Post-process if needed
For ISODate or ObjectId fields, run an aggregation pipeline with $set and $toDate to convert string dates into BSON dates. This step is one-time after the initial load.
Real-world examples
Common situations where this approach makes a real difference:
Seed development database
A developer seeds a local MongoDB with sample customer data from a CSV. The conversion to JSON array followed by mongoimport --jsonArray populates the collection in one command.
Reference data update
An ops engineer updates a reference collection of country codes. The CSV from the data team converts to JSON and loads via mongoimport with the upsert flag to update existing documents.
Atlas data load via UI
A non-developer loads CSV data into MongoDB Atlas using the import UI which prefers JSON. Conversion in FixTools produces the file the UI accepts directly.
Migrating from a relational dump
A platform engineer migrates a Postgres table dump (exported as CSV) into MongoDB. Conversion to JSON array with nested fields produces documents that match the new MongoDB schema.
Pro tips
Get better results with these expert suggestions:
Use --jsonArray with mongoimport
Always pass --jsonArray when the file is a JSON array. Without the flag, mongoimport expects one document per line (JSONL) and will fail on a wrapped array. FixTools supports both output modes if you prefer the JSONL flow.
Drop _id from the CSV
Let MongoDB generate ObjectIds on insert by omitting the _id field from the CSV. Trying to import string _id values where ObjectId is expected causes type mismatches in indexes downstream.
Use ISO 8601 for dates
Store dates in the CSV as ISO 8601 strings like 2024-03-15T10:30:00Z. After import run an update with $toDate to convert them to BSON dates. This is cleaner than trying to embed MongoDB Extended JSON in the conversion step.
Verify counts after import
After mongoimport finishes, run db.collection.countDocuments() and compare against the array length in your JSON file. Mismatches indicate failed inserts due to validation rules or schema constraints.
Frequently asked questions
Related guides
More use-case guides for the same tool:
Related tools
Other tools you might find useful:
Ready to get started?
Open CSV to JSON to review its free limits and processing method.
Open CSV to JSON →Free tier · No account needed · Transparent limits