SQL.SetParamsWithJSON
---------------------

Sets parameters based on values in JSON.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [SQL](component_SQL.md) | [10.2](newinversion102.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "SQL.SetParamsWithJSON"; Command; JSON ) 

**MBS**( **"SQL.SetParamsWithJSON";** /\* Sets parameters based on values in JSON. \*/  
**$Command**; /\* The command reference number gained with [SQL.NewCommand](SQLNewCommand.md). \*/   
**$JSON**) /\* The JSON object with values for the items.e.g. "{ \\"Index\\": 123 }" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| Command | The command reference number gained with [SQL.NewCommand](SQLNewCommand.md). | $Command |
| JSON | The JSON object with values for the items. | "{ \\"Index\\": 123 }" |

### Result

Returns OK or error.

### Description

Sets parameters based on values in JSON.  
If a parameter has a known type, we convert JSON to that type: Null, Double, Integer, String, Boolean.  
If type of parameter is not known, we check JSON type and pass boolean, numbers or texts through.  
Setting BLOB may not work with this function.  
If JSON value is array or object, we encode as text and set field to text value.  
Parameters not present in JSON are skipped.  
### Examples

Run insert with JSON:

 # Create insert command with setting values   
Set Variable \[ $Command ; Value: MBS ("[SQL.NewCommand](SQLNewCommand.md)"; $Connection ; "INSERT INTO 'Test' (FirstName, LastName, Birthday, NumberOfOrders, TotalSales) VALUES (:FirstName,:LastName,:Birthday,:NumberOfOrders,:TotalSales)") \]   
  
\# build some JSON   
Set Variable \[ $json ; Value: "{}" \]   
Set Variable \[ $json ; Value: MBS ( "[JSON.AddStringToObject](JSONAddStringToObject.md)"; $json ; "FirstName"; SQLite fun::FirstName ) \]   
Set Variable \[ $json ; Value: MBS ( "[JSON.AddStringToObject](JSONAddStringToObject.md)"; $json ; "LastName"; SQLite fun::LastName ) \]   
Set Variable \[ $json ; Value: MBS ( "[JSON.AddStringToObject](JSONAddStringToObject.md)"; $json ; "Birthday"; SQLite fun::Birthday ) \]   
Set Variable \[ $json ; Value: MBS ( "[JSON.AddNumberToObject](JSONAddNumberToObject.md)"; $json ; "NumberOfOrders"; SQLite fun::NumberOfOrders ) \]   
Set Variable \[ $json ; Value: MBS ( "[JSON.AddNumberToObject](JSONAddNumberToObject.md)"; $json ; "TotalSales"; SQLite fun::TotalSales ) \]   
Set Variable \[ $result ; Value: MBS ("SQL.SetParamsWithJSON"; $Command ; $json ) \]   
  
\# Run it   
Show Custom Dialog \[ "JSON" ; MBS ( "[SQL.GetParamsAsJSON](SQLGetParamsAsJSON.md)"; $Command ) \]   
Set Variable \[ $result ; Value: MBS ("[SQL.Execute](SQLExecute.md)"; $Command ) \]   
  
\# Cleanup   
Set Variable \[ $result2 ; Value: MBS ("[SQL.Commit](SQLCommit.md)"; $Connection ) \]   
Set Variable \[ $result2 ; Value: MBS ("[SQL.FreeCommand](SQLFreeCommand.md)"; $Command ) \]   
If \[ $result ≠ "OK" \]   
 Show Custom Dialog \[ "Error: " &amp; $result \]   
Else  
 Show Custom Dialog \[ "Record exported." \]   
End If  
### See also

- [JSON.AddNumberToObject](JSONAddNumberToObject.md)
- [JSON.AddStringToObject](JSONAddStringToObject.md)
- [SQL.Commit](SQLCommit.md)
- [SQL.Execute](SQLExecute.md)
- [SQL.FreeCommand](SQLFreeCommand.md)
- [SQL.GetParamsAsJSON](SQLGetParamsAsJSON.md)
- [SQL.NewCommand](SQLNewCommand.md)

### Release notes

- **Version 10.2**
    - Added [SQL.GetFieldsAsJSON](https://www.mbsplugins.eu/SQLGetFieldsAsJSON.shtml), [SQL.GetParamsAsJSON](https://www.mbsplugins.eu/SQLGetParamsAsJSON.shtml), [SQL.GetRecordsAsJSON](https://www.mbsplugins.eu/SQLGetRecordsAsJSON.shtml) and [SQL.SetParamsWithJSON](https://www.mbsplugins.eu/SQLSetParamsWithJSON.shtml) functions.

### Example Databases

- [SQL to other databases/SQLite fun](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SQL%20to%20other%20databases/SQLite%20fun.shtml#5ScriptAnchor_)

### Blog Entries

- [Embrace JSON](https://www.mbsplugins.de/archive/2020-09-29/Embrace_JSON/monkeybreadsoftware_blog_filemaker)
- [News about the MBS FileMaker Plugin 10.2](https://www.mbsplugins.de/archive/2020-05-19/News_about_the_MBS_FileMaker_P/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 10.2pr1](https://www.mbsplugins.de/archive/2020-04-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)

This function is free to use.

Created 11st March 2020 , last changed 11st March 2020

  
[SQL.SetParamValues](SQLSetParamValues.md) - [SQL.isAlive](SQLisAlive.md)

[HTML Version](SQLSetParamsWithJSON.shtml)