SQL.GetRecordsAsJSON
--------------------

Queries records of current result set as JSON array.

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

MBS( "SQL.GetRecordsAsJSON"; Command ) 

**MBS**( **"SQL.GetRecordsAsJSON";** /\* Queries records of current result set as JSON array. \*/  
**$Command**) /\* The command reference number gained with [SQL.NewCommand](SQLNewCommand.md). \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| Command | The command reference number gained with [SQL.NewCommand](SQLNewCommand.md). | $Command |

### Result

Returns JSON or error.

### Description

Queries records of current result set as JSON array.  
Each array entry contains a record converted to JSON.  
  
Dates, Intervals and BLOBs get converted to text. Boolean, Integer, Numeric and Double types are converted to numbers in JSON. Boolean is passed through as boolean. Null or unknown field types are returned as NULL in JSON.  
### Examples

Show record as JSON:

 # Create select and run it   
Set Variable \[ $Command ; Value: MBS ("[SQL.NewCommand](SQLNewCommand.md)"; $Connection ; "SELECT \* FROM Test") \]   
\# Run it   
Set Variable \[ $result ; Value: MBS ("[SQL.Execute](SQLExecute.md)"; $Command ) \]   
If \[ $result ≠ "OK" \]   
 Show Custom Dialog \[ "Error: " &amp; $result \]   
Else  
 Show Custom Dialog \[ "JSON" ; MBS ( "SQL.GetRecordsAsJSON"; $Command ) \]   
End If  
\# Cleanup   
Set Variable \[ $result2 ; Value: MBS ("[SQL.FreeCommand](SQLFreeCommand.md)"; $Command ) \]  
### See also

- [SQL.Execute](SQLExecute.md)
- [SQL.FreeCommand](SQLFreeCommand.md)
- [SQL.GetFieldsAsJSON](SQLGetFieldsAsJSON.md)
- [SQL.GetRecordsAsText](SQLGetRecordsAsText.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/ODBC Query](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SQL%20to%20other%20databases/ODBC%20Query.shtml#2ScriptAnchor_)
- [SQL to other databases/SQLite fun](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SQL%20to%20other%20databases/SQLite%20fun.shtml#6ScriptAnchor_)

### Blog Entries

- [Moving data from ODBC to FileMaker via script](https://www.mbsplugins.de/archive/2023-02-12/Moving_data_from_ODBC_to_FileM/monkeybreadsoftware_blog_filemaker)
- [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.GetParamsAsJSON](SQLGetParamsAsJSON.md) - [SQL.GetRecordsAsText](SQLGetRecordsAsText.md)

[HTML Version](SQLGetRecordsAsJSON.shtml)