JSON import

Upload a JSON document and turn every collection in it into a model with its own endpoints. You decide per nested object whether it becomes a related model, extra fields or JSON text.

How JSON Import works

JSON Import reads a .json file, such as an export from MongoDB or another document store, and recreates its data in SearchAPI. Each collection in the file becomes a new model with a set of endpoints and an Elasticsearch index, and its records are written into that index.

Objects and arrays of objects inside a record can become their own models, linked to the record they came from. For example, the comments of a blog post become a comments model whose records point back to their post.

Unlike CSV / XLSX import, which handles one file and one model at a time, JSON Import creates many related models in a single job. It works on the same review page as SQL import, and every model is created by the import itself — collections are never linked to models that already exist in your account.

Prerequisites

Upload the file

  1. In the sidebar, click Data Import.
  2. Click + New / Draft JSON Import.
  3. Select the target API and API Version.
  4. Choose your .json file.
    New JSON Import page with API, API version and file fields New JSON Import — select API, version and file
  5. Click Analyze JSON file.

Result: the file's format is checked and you are taken to the import's review page. While Analyzing JSON file… is shown, the records are read in the background; a file close to 100 MB can take up to a minute. Nothing is created yet at this point.

A file that breaks the supported format is rejected with a message naming the rule it breaks, and no draft is created.

Drafts

Every change you make on the review page is saved automatically as a draft. JSON imports you started but haven't submitted appear under Continue a draft import on the upload page, where you can resume or remove them.

Review collections

The review page lists every collection on the left by its model name. A root array is one collection named after the file: Blog Posts.json becomes blog_posts. Collections created from nested fields are listed too, named after their field.

A red alert icon next to a collection means it has an issue that blocks the import; hover over it to see the details. A yellow icon is a non-blocking warning. Click a collection to open its settings. Use the trash icon to leave a collection out of the import, and the + icon to add it back.

JSON Import review page with the collection list and field settings Review page — collection list and field settings

Choose how nested fields are imported

  1. On the review page, click a collection.
  2. Under Nested fields, find the object or array field.
  3. In Import as, pick one of the options. The Becomes column shows the result.
    Nested fields section with an Import as choice per field Nested fields — choosing how each object or array is imported

Result: the file is analyzed again with the new choice, and collections can appear in or disappear from the list on the left.

Import as Available for Result
Separate model Objects, arrays of objects A model named after the field, linked to the record. An object is linked by a <field>_id field on the record; an array's records are linked back by a <collection>_id field.
Flatten into fields Objects One field per key on the record: meta.lang becomes meta_lang.
Keep as JSON text Objects, arrays of objects One text field holding the value as JSON.
Don't import Objects, arrays of objects The field is left out.

The default is Separate model for an object that has a key (id, uuid or <field>_id) and for an array of objects whose records have a key, and Flatten into fields for other objects. An array of plain values, such as ["red", "blue"], is always kept as JSON text.

Example — a post with an author and comments, both imported as separate models:

{"posts": [
  {
    "id": 1,
    "title": "Hello",
    "author": {"id": 7, "name": "Ada"},
    "comments": [{"id": 10, "body": "Nice"}]
  }
]}

This creates three models: posts with an author_id field, author, and comments with a posts_id field. An author that appears under several posts is written once.

Note: A separate model needs a primary key, and the link fields hold its values. If the object has no key, select its collection and pick a primary key field; it can't use a generated id, because the records that link to it need a real value.

Set the model and field settings

  1. On the review page, click a collection.
  2. Under Field settings, check the Model name and Endpoint path. Both must be unique, also among the other collections of this import.
  3. Make sure the collection has a primary key: pick a field in the Primary Key column, or check Generate unique auto increment id and enter a Primary Key Column name.
  4. Adjust the field table: Model Field Name, Type, Required, Searchable and Visible In Related Model. Use the trash icon to leave a field out.

Result: the collection no longer shows a red alert icon. These settings work as in SQL import; see its table settings, field settings, relations and self-referencing sections for the details.

A primary key is detected when id, uuid or <collection>_id holds a unique value. A string key is imported as keyword, because a text field can't be a primary key; pick another string field the same way after changing its Type to keyword.

Start the import

  1. Make sure no collection shows a red alert icon.
  2. Click Start import.

Result: each collection gets its own model, endpoints and Elasticsearch index, and its records are written in the background. The review page shows a status for each collection; selecting one shows how many records were written or failed and links to its import job. The new endpoints have no API keys yet — assign keys and deploy the version as usual (see API keys and API versioning). Each collection's job also appears in the import job list.

Reference

Supported JSON format

The file must be valid JSON (RFC 8259) with one of these roots:

  • An array of records — [{...}, {...}], imported as one collection named after the file.
  • An object of collections — {"posts": [{...}], "users": [{...}]}, where every top-level key holds an array of records.

Every record must be an object. MongoDB exports made with mongoexport --jsonArray are supported: Extended JSON values such as {"$oid": "..."}, {"$date": ...} and {"$numberDecimal": "..."} are read as plain values, and dates are converted to UTC without milliseconds.

Not supported:

  • JSON Lines (NDJSON) and Elasticsearch _bulk files — put the records in a JSON array instead.
  • API responses with extra top-level keys, such as {"data": [...], "has_more": true}, and records keyed by id, such as {"0": {...}, "1": {...}}.
  • Values outside the JSON standard: NaN, comments, single quotes and trailing commas.

Limits

Limit Value
File size100 MB
Nesting depth of the document64 levels
Depth of separate models 5 levels; deeper objects can only be flattened or kept as JSON text
Rows in a related model10 000, as in SQL import

Field names

Keys are converted to valid field names: lowercase letters, digits and underscores. authorId becomes author_id, and MongoDB's _id becomes id. Two keys that end up with the same name in one record get a _2, _3… suffix. A field named <name>_id links to a collection named <name> or its plural when that collection has a primary key.

Type detection

The type of each field is detected from all of its values:

Values Field type
Whole numbers between -2 147 483 648 and 2 147 483 647integer
Larger whole numberslong
Numbers with decimalsfloat
true / falseboolean
2024-03-15date
2024-03-15 10:30:00 or 2024-03-15T10:30:00date with date and time
Primary keys and _id fields holding textkeyword
Anything else, including JSON texttext

Empty values and null don't count. A date with a time zone or milliseconds stays text; change its Type if you need it as a date.

Records that fail

The first record that holds a value for a field sets its shape: an object, an array of objects or a plain value. A later record holding a different shape for that field isn't saved and is listed as a failed row in its import job, for example:

Field "author" holds a plain value where the first record has an object; fix the record and import it again.

A record without the key its child records link with isn't saved either, and neither are its children. When the same record appears several times, the first one is kept.

Last updated: December 3, 2026