Free · Fast · Privacy-first

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

Runs in your browser
JSON output
Run the tool to see a task-specific result.

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
IframeResponsiveAttribution included

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. 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. 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. 3

    Download the array

    Save the JSON as a file. Use a descriptive name like users.json that matches the target collection.

  4. 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. 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:

1

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.

2

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.

3

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.

4

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.

FAQ

Frequently asked questions

mongoimport --uri mongodb://localhost:27017/yourdb --collection yourcoll --file path/to/converted.json --jsonArray. The --jsonArray flag is required when the file is a JSON array. Without it mongoimport expects JSONL.
Usually not. Let MongoDB generate ObjectIds on insert by omitting _id from the CSV. Only include _id if you have specific values you want to preserve across systems, and even then store them as strings rather than trying to embed ObjectId syntax.
Use dot-notation in CSV headers like address.city. The converter builds nested objects automatically and mongoimport stores them as BSON sub-documents matching the dot path.
No. CSV cells are converted to JSON strings or numbers depending on column inference. For BSON Date type, store ISO 8601 strings in the CSV and run a $toDate aggregation after import to convert them to real Date objects.
Store the hex string in the CSV and run a post-import update to convert string references to ObjectId. The converter does not embed Extended JSON syntax because it keeps the output portable to consumers other than MongoDB.
Yes. Use --mode upsert with --upsertFields specifying which fields identify a document. Existing matching documents update, new documents insert. The JSON shape is identical to a plain import.
Atlas accepts the same mongoimport command with an Atlas connection string. Alternatively use the Atlas data import UI and upload the JSON file directly. Both routes accept the array shape FixTools produces.
Check the validator rules against the imported document shape. Common issues include type mismatches (string where number expected), missing required fields, or extra fields when additionalProperties is false. Adjust the CSV or relax the schema as appropriate.
Yes, but consider creating indexes after the import rather than before. Importing into an indexed collection is slower because each insert updates the indexes. For large imports, drop indexes first, import, then recreate indexes.

Related guides

More use-case guides for the same tool:

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

Source-backed reference

JSON standards quick reference

Concise, standards-backed facts for developers working with JSON debugging and validation. Each rule links to a primary specification so it can be independently verified before you rely on it in code, documentation, or an incident report.

JSON standard
RFC 8259 defines JSON as a text format for serializing structured data. JSON values may be objects, arrays, strings, numbers, true, false, or null.
Verify in RFC 8259
Strings and object keys
JSON strings and object member names use double quotation marks. Single-quoted strings are not valid JSON syntax.
Verify in RFC 8259 §7
Trailing commas
The JSON grammar does not allow a comma after the final member of an object or the final element of an array.
Verify in RFC 8259 §4–5
Interoperability
ECMA-404 describes the JSON syntax independently of any programming language, which is why standard parsers can exchange the same JSON text across runtimes.
Verify in ECMA-404

Common invalid → valid JSON examples

Trailing comma

{"a":1,}{"a":1}

Single-quoted key

{'a':1}{"a":1}

Unsupported literal

{"score":NaN}{"score":null}

Built for verification, not just extraction

Direct answers are paired with primary sources and concrete examples. That makes this page useful to developers and also gives search and answer systems a clear, verifiable statement to reference instead of an unsupported summary.