JSON.InsertRecord
-----------------

Inserts a new record in a table in one line using JSON.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [JSON](component_JSON.md) | [14.4](newinversion144.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "JSON.InsertRecord"; FileName; TableName; JSON ) 

**MBS**( **"JSON.InsertRecord";** /\* Inserts a new record in a table in one line using JSON. \*/  
**$FileName**; /\* The file name of where the table is inside. Can be empty to look for the table in all files.  
  
Using a table in another database file may require you adding the other file as an external data source and adding the external table to your relationship graph to grant access.e.g. Get(FileName) \*/   
**$TableName**; /\* The name of the table to insert record into.  
Can be ID of table, so we lookup name by ID.   
Can be result of GetFieldName() function as we remove field name automatically.e.g. "Assets" \*/   
**$JSON**) /\* The JSON object with the record. \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| FileName | The file name of where the table is inside. Can be empty to look for the table in all files.      Using a table in another database file may require you adding the other file as an external data source and adding the external table to your relationship graph to grant access. | Get(FileName) |
| TableName | The name of the table to insert record into.   Can be ID of table, so we lookup name by ID.    Can be result of GetFieldName() function as we remove field name automatically. | "Assets" |
| JSON | The JSON object with the record. |  |

### Result

Returns OK or error.

### Description

Inserts a new record in a table in one line using JSON.  
You pass to this function table name (and optional filename).  
Then you pass a JSON with a field names and values for each field you like to set in the new record.  
  
As we can't know the new ID assigned for the record, you can help yourself by passing in an UUID for a field and later select that to get the auto assigned primary key (or have the UUID be the primary key, so you don't need a query).  
  
See also [JSON.UpdateRecord](JSONUpdateRecord.md) to update a record.  
You can specify fields and table via IDs and the plugin will lookup them for you at runtime. Table IDs and table names must be unique across all open files for this to work correctly.  
  
You can use [FM.ExecuteSQL.LastSQL](FMExecuteSQLLastSQL.md) function to see later what SQL was created and run.  
The [SQL](component_SQL.md) functions in FileMaker do not trigger OnWindowsTransaction script trigger.  
  
Does not take part in transactions in FileMaker. Changes are made directly to the database, so you can't revert them later with Revert Transaction script step.  
  
We auto convert text values to date, time or timestamp if the plugin sees the fields having such a type. Otherwise the type of JSON value defines the data type. If JSON contains an array or object, we make text from it.  
  
You can use [FM.SQL.Execute](FMSQLExecute.md) function to query records in FileMaker and get them as JSON with [FM.SQL.JSONRecords](FMSQLJSONRecords.md) function. If needed, use [JSON.ReplaceEvaluate](JSONReplaceEvaluate.md) or [JSON.Replace](JSONReplace.md) to adjust the JSON and make modifications. Then use JSON.InsertRecord or [JSON.InsertOrUpdateRecord](JSONInsertOrUpdateRecord.md) to insert them.  
### Examples

Insert records with JSON:

 MBS ("JSON.InsertRecord"; ""; "Contacts"; "{\\"FirstName\\": \\"John\\", \\"TheNumber\\": 123}")  
Insert with repeating fields using \[\]:

 MBS ("JSON.InsertRecord"; ""; "Assets"; "{\\"SomeField\[1\]\\": \\"John\\", \\"SomeField\[2\]\\": \\"Miller\\"}")  
### See also

- [FM.InsertRecord](FMInsertRecord.md)
- [FM.SQL.Execute](FMSQLExecute.md)
- [FM.SQL.JSONRecords](FMSQLJSONRecords.md)
- [JSON.DeleteRecord](JSONDeleteRecord.md)
- [JSON.InsertOrUpdateRecord](JSONInsertOrUpdateRecord.md)
- [JSON.InsertRecords](JSONInsertRecords.md)
- [JSON.Replace](JSONReplace.md)
- [JSON.ReplaceEvaluate](JSONReplaceEvaluate.md)
- [JSON.UpdateRecord](JSONUpdateRecord.md)
- [SQL.InsertRecords](SQLInsertRecords.md)

### Release notes

- **Version 16.4**
    - Improved [JSON.InsertRecord](https://www.mbsplugins.eu/JSONInsertRecord.shtml), [JSON.InsertRecords](https://www.mbsplugins.eu/JSONInsertRecords.shtml), [JSON.InsertOrUpdateRecord](https://www.mbsplugins.eu/JSONInsertOrUpdateRecord.shtml), [JSON.UpdateRecord](https://www.mbsplugins.eu/JSONUpdateRecord.shtml) and [JSON.UpdateRecords](https://www.mbsplugins.eu/JSONUpdateRecords.shtml) to detect containers encoded as JSON object with name and base64 encoded data and decode them.
- **Version 16.3**
    - Fixed an issue with [JSON.InsertRecord](https://www.mbsplugins.eu/JSONInsertRecord.shtml) crashing when you have illegal type mismatches in the parameters.
- **Version 16.1**
    - Fixed an issue with [JSON.InsertRecord](https://www.mbsplugins.eu/JSONInsertRecord.shtml) where we passed date as timestamp and FileMaker complained about incompatible types.
- **Version 16.0**
    - Fixed a problem with [JSON.InsertRecord](https://www.mbsplugins.eu/JSONInsertRecord.shtml) not handling timestamps correctly.
- **Version 14.5**
    - Added [JSON.InsertRecords](https://www.mbsplugins.eu/JSONInsertRecords.shtml) function to insert array of records in JSON.
    - Improved [JSON.InsertRecord](https://www.mbsplugins.eu/JSONInsertRecord.shtml) to be a bit faster and data type conversion to do numbers and texts, too.
- **Version 14.4**
    - Added [JSON.InsertRecord](https://www.mbsplugins.eu/JSONInsertRecord.shtml) and [JSON.InsertOrUpdateRecord](https://www.mbsplugins.eu/JSONInsertOrUpdateRecord.shtml) functions.

### Example Databases

- [JSON/JSON Insert and Update](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JSON/JSON%20Insert%20and%20Update.shtml#1ScriptAnchor_)

### Blog Entries

- [MBS FileMaker Plugin, version 16.4pr7](https://www.mbsplugins.de/archive/2026-09-17/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 16.3pr1](https://www.mbsplugins.de/archive/2026-06-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 16.1pr2](https://www.mbsplugins.de/archive/2026-02-06/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 15.6pr4](https://www.mbsplugins.de/archive/2025-12-22/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 14.5pr5](https://www.mbsplugins.de/archive/2024-10-28/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [New in MBS FileMaker Plugin 14.4](https://www.mbsplugins.de/archive/2024-09-24/New_in_MBS_FileMaker_Plugin_14/monkeybreadsoftware_blog_filemaker)
- [Neues MBS Plugin 14.4 für Claris FileMaker](https://www.mbsplugins.de/archive/2024-09-17/Neues_MBS_Plugin_144_für_Clar/monkeybreadsoftware_blog_filemaker)
- [MBS Plugin 14.4 for Claris FileMaker](https://www.mbsplugins.de/archive/2024-09-17/MBS_Plugin_144_for_Claris_File/monkeybreadsoftware_blog_filemaker)
- [Insert or update with JSON](https://www.mbsplugins.de/archive/2024-08-28/Insert_or_update_with_JSON/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 14.4pr3](https://www.mbsplugins.de/archive/2024-08-21/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 20th August 2024 , last changed 14th October 2024

  
[JSON.InsertOrUpdateRecord](JSONInsertOrUpdateRecord.md) - [JSON.InsertRecords](JSONInsertRecords.md)

[HTML Version](JSONInsertRecord.shtml)