Topics
All
MacOS
(Only)
Windows
(Only)
Linux
(Only, Not)
iOS
(Only, Not)
Components
Crossplatform Mac & Win
Server
Client
Old
Deprecated
Guides
Examples
Videos
New in version:
12.2
12.3
12.4
12.5
13.0
13.1
13.2
13.3
13.4
13.5
Statistic
FMM
Blog
Returns a row as JSON object.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
FM FMSQL JSON | 8.1 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameter | Description | Example | Flags |
---|---|---|---|
SQLref | The reference number returned by FM.SQL.Execute function. | $SQLRef | |
Row | The row you like to get. 0 for first row. |
1 | |
FieldNames | A list of field names for the JSON. If you have duplicate entries in the field names, the resulting JSON will have duplicate keys, which can be a problem. |
"Model¶Names" | |
Flags | The flags for the json creation. Pass 1 to get all values as text (empty text instead of null). Pass 2 to get all dates, times and timestamps in SQL format (formatted by plugin) instead of GetAsText() by FileMaker. Pass 4 to get arrays instead of objects for the individual rows. Pass 8 to get containers as objects with name, size and data entries. (new in v12.1) |
1+2 | Optional |
Returns JSON text or error.
Query JSON record:
# run query to get some data
Set Variable [ $sql ; Value: MBS( "FM.SQL.Execute"; ""; "SELECT \"First\", \"Last\", Company, \"Photo Container\" FROM Contacts") ]
# query data
Set Variable [ $json ; Value: MBS( "FM.SQL.JSONRecord"; $sql; 0; "First¶Last¶Company¶Photo"; 2) ]
# store result
Set Field [ Contacts::Output ; $json ]
# free memory
Set Variable [ $xml ; Value: MBS( "FM.SQL.Release"; $sql) ]
Query record as JSON:
Let ( [
fields = MBS( "FM.QueryFieldsForTableName"; "Contacts");
Records = MBS( "FM.SQL.Execute"; ""; "SELECT \"" & substitute(fields; ¶; "\", \"") & "\" FROM \"Contacts\" WHERE \"First\" = ?"; "Joe");
json = MBS( "FM.SQL.JSONRecord"; Records; 0; fields);
r = MBS( "FM.SQL.Release"; Records )]
; json )
Query current record as JSON:
Let([
// get field list
fields = MBS( "FM.QueryFieldsForTableName"; Get(LayoutTableName));
// query the fields using that fieold list for current record
sql = MBS( "FM.SQL.Execute"; Get(FileName); "SELECT \"" & Substitute(fields; ¶; "\", \"") & "\" FROM \"" & Get ( LayoutTableName ) & "\" WHERE RowID = ?"; Get( RecordID ));
// and query JSON
json = MBS( "FM.SQL.JSONRecord"; sql; 0; fields );
// free SQL result
R = MBS("FM.SQL.Release"; sql)
]; json)
This function checks for a license.
Created 4th March 2018, last changed 1st May 2023