Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
JSON.CreateArrayRef
Creates empty array reference.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
JSON | 6.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
none
Result
Returns reference number or error.
Description
Creates empty array reference.Please use JSON.Release later to free the json object.
You can pass the reference number to all MBS JSON functions instead of JSON text.
Examples
Test array reference functions:
# create array reference
$ref = MBS( "JSON.CreateArrayRef" )
# add some numbers
$r = MBS( "JSON.AddNumberToArray"; $ref; 1; 2; 3 )
# add some texts
$r = MBS( "JSON.AddStringToArray"; $ref; "Hello"; "World" )
# get JSON text for this array:
$text = MBS( "JSON.Compact"; $ref)
# free memory
$r = MBS( "JSON.Release"; $ref )
Use While loop to create JSON array:
Let ( [
// Create array object
j = MBS( "JSON.CreateArrayRef" );
// make a loop to add numbers
r = While ( $i = 0 ; $i < 10 ; [ r = MBS( "JSON.AddNumberToArray"; j; $i ); $i = $i + 1 ] ; $i );
// format the result
text = MBS( "JSON.Format"; j );
// free json
r = MBS( "JSON.Release"; j )
];
// return result as text
text )
Example result:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Create complex JSON:
Set Variable [ $a ; Value: MBS( "JSON.CreateArrayRef" ) ]
#
# first entry
Set Variable [ $o ; Value: MBS( "JSON.CreateObjectRef" ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddNumberToObject"; $o; "FieldType"; 11 ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddNullToObject"; $o; "FieldName" ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddStringToObject"; $o; "Value"; "Julien" ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddBooleanToObject"; $o; "EmptyMatch"; False ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddItemToArray"; $a; $o) ]
Set Variable [ $r ; Value: MBS( "JSON.Release"; $o) ]
#
# second entry
Set Variable [ $o ; Value: MBS( "JSON.CreateObjectRef" ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddNumberToObject"; $o; "FieldType"; 23 ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddNullToObject"; $o; "FieldName" ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddStringToObject"; $o; "Value"; "Stadel" ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddBooleanToObject"; $o; "EmptyMatch"; False ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddItemToArray"; $a; $o) ]
Set Variable [ $r ; Value: MBS( "JSON.Release"; $o) ]
#
# surrounding object
Set Variable [ $o ; Value: MBS( "JSON.CreateObjectRef" ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddItemToObject"; $o; "Data"; $a) ]
Set Variable [ $r ; Value: MBS( "JSON.AddNumberToObject"; $o; "Id"; 123 ) ]
Set Variable [ $r ; Value: MBS( "JSON.Release"; $a) ]
#
# put in final object
Set Variable [ $j ; Value: MBS( "JSON.CreateObjectRef" ) ]
Set Variable [ $r ; Value: MBS( "JSON.AddItemToObject"; $j; "Address"; $o) ]
Set Variable [ $r ; Value: MBS( "JSON.Release"; $o) ]
#
Set Field [ JSON::JSON ; MBS("JSON.Colorize"; MBS("JSON.Format"; $j)) ]
Set Variable [ $r ; Value: MBS( "JSON.Release"; $j) ]
See also
- JSON.AddBooleanToObject
- JSON.AddItemToArray
- JSON.AddNumberToArray
- JSON.AddStringToObject
- JSON.Colorize
- JSON.CreateArray
- JSON.CreateObject
- JSON.CreateObjectRef
- JSON.Format
- JSON.Release
Example Databases
Blog Entries
- Data structures in MBS Plugin
- With JSON in excellent form
- Fun with While function in FileMaker
- MBS FileMaker Plugin 6.0 for OS X/Windows
- MBS FileMaker Plugin, version 6.0pr6
This function is free to use.
Created 5th January 2016, last changed 20th November 2019