Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

JSON.AddItemToArray

Adds an item to an array.

Component Version macOS Windows Linux Server iOS SDK
JSON 2.7 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "JSON.AddItemToArray"; json; json2... )   More

Parameters

Parameter Description Example
json A JSON text or reference. [1,2,3]
json2... A JSON text or reference. 4

Result

Returns JSON code.

Description

Adds an item to an array.

With version 6, you can pass several parameters to add several entries to the array.
When adding to a JSON reference, the function returns that reference number.

This function takes variable number of parameters. Pass as much parameters as needed separated by the semicolon in FileMaker.
Please repeat json2 parameter as often as you need.

Examples

Adds an item to array:

MBS( "JSON.AddItemToArray"; "[1,2,3]"; MBS("JSON.CreateNumber"; 4) )

Example result:
[1, 2, 3, 4]

Add three items to empty array:

MBS( "JSON.AddItemToArray"; "[]"; "1"; "2"; "\"Heinz\"")

Example result:
[1, 2, "Heinz"]

Adds an item to the array:

MBS( "JSON.AddItemToArray"; "[]"; 67 )

Example result:
[67]

Build a JSON object with an array of objects in one Let:

let([

// build first object
o1 = "{}";
o1 = MBS("JSON.AddStringToObject"; o1; "FirstName"; "Joe");
o1 = MBS("JSON.AddStringToObject"; o1; "LastName"; "Miller");

// build first object
o2 = "{}";
o2 = MBS("JSON.AddStringToObject"; o2; "FirstName"; "Zoe");
o2 = MBS("JSON.AddStringToObject"; o2; "LastName"; "Jones");

// add them to array:
a1 = "[]";
a1 = MBS("JSON.AddItemToArray"; a1; o1);
a1 = MBS("JSON.AddItemToArray"; a1; o2);

// make result
r = "{}";
r = MBS( "JSON.AddItemToObject"; r; "people"; a1 );
r = MBS( "JSON.AddStringToObject"; r; "count"; 2 )
];r)

Example result:
{ "people": [ { "FirstName": "Joe", "LastName": "Miller" }, { "FirstName": "Zoe", "LastName": "Jones" } ], "count": "2" }

See also

Release notes

Example Databases

Blog Entries

This function checks for a license.

Created 18th August 2014, last changed 7th February 2023


JSON.AddFalseToObject - JSON.AddItemToObject