JSON.AddItemToArray
-------------------

Adds an item to an array.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [JSON](component_JSON.md) | [2.7](newinversion27.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "JSON.AddItemToArray"; JSON; json2... ) 

**MBS**( **"JSON.AddItemToArray";** /\* Adds an item to an array. \*/  
**$JSON**; /\* A JSON text or reference.e.g. \[1,2,3\] \*/   
**$json2...**) /\* A JSON text or reference.e.g. 4 \*/ 

### 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](JSONCreateNumber.md)"; 4) )  
<small>  
Example result:   
\[1 , 2 , 3 , 4 \] </small>Add three items to empty array:

 MBS ( "JSON.AddItemToArray"; "\[\]"; "1"; "2"; "\\"Heinz\\"")  
<small>  
Example result:   
\[1 , 2 , "Heinz" \] </small>Adds an item to the array:

 MBS ( "JSON.AddItemToArray"; "\[\]"; 67 )  
<small>  
Example result:   
\[67 \] </small>Build a JSON object with an array of objects in one Let:

 let(\[  
  
// build first object  
o1 = "{}";  
o1 = MBS ("[JSON.AddStringToObject](JSONAddStringToObject.md)"; o1; "FirstName"; "Joe");  
o1 = MBS ("[JSON.AddStringToObject](JSONAddStringToObject.md)"; o1; "LastName"; "Miller");  
  
// build first object  
o2 = "{}";  
o2 = MBS ("[JSON.AddStringToObject](JSONAddStringToObject.md)"; o2; "FirstName"; "Zoe");  
o2 = MBS ("[JSON.AddStringToObject](JSONAddStringToObject.md)"; 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](JSONAddItemToObject.md)"; r; "people"; a1 );  
r = MBS ( "[JSON.AddStringToObject](JSONAddStringToObject.md)"; r; "count"; 2 )   
\];r)  
<small>  
Example result:   
{ "people" : \[ { "FirstName" : "Joe" , "LastName" : "Miller" }, { "FirstName" : "Zoe" , "LastName" : "Jones" } \], "count" : "2" } </small>### See also

- [JSON.AddArrayToArray](JSONAddArrayToArray.md)
- [JSON.AddBooleanToObject](JSONAddBooleanToObject.md)
- [JSON.AddItemToObject](JSONAddItemToObject.md)
- [JSON.AddNumberToArray](JSONAddNumberToArray.md)
- [JSON.AddStringToArray](JSONAddStringToArray.md)
- [JSON.AddStringToObject](JSONAddStringToObject.md)
- [JSON.AddValueToArray](JSONAddValueToArray.md)
- [JSON.CreateArrayRef](JSONCreateArrayRef.md)
- [JSON.CreateNumber](JSONCreateNumber.md)
- [JSON.CreateObjectRef](JSONCreateObjectRef.md)

### Release notes

- **Version 14.4**
    - Improved [JSON](https://www.mbsplugins.eu/component_JSON.shtml) functions to return error if you pass non JSON parameters to [JSON.AddItemToArray](https://www.mbsplugins.eu/JSONAddItemToArray.shtml), [JSON.AddItemToObject](https://www.mbsplugins.eu/JSONAddItemToObject.shtml), [JSON.Replace](https://www.mbsplugins.eu/JSONReplace.shtml) and related functions.
- **Version 11.3**
    - Changed [JSON.GetObjectItemTree](https://www.mbsplugins.eu/JSONGetObjectItemTree.shtml), [JSON.GetObjectItemTreeRef](https://www.mbsplugins.eu/JSONGetObjectItemTreeRef.shtml), [JSON.AddArrayToArray](https://www.mbsplugins.eu/JSONAddArrayToArray.shtml) and [JSON.AddItemToArray](https://www.mbsplugins.eu/JSONAddItemToArray.shtml) to ignore empty parameters.

### Example Databases

- [JSON/JSON Benchmark](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JSON/JSON%20Benchmark.shtml#2ScriptAnchor_)
- [Mac and iOS/MapKit/MapView BeeExample](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Mac%20and%20iOS/MapKit/MapView%20BeeExample.shtml#28ScriptAnchor_)
- [Mac and iOS/MapKit/MapView Click Polygons](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Mac%20and%20iOS/MapKit/MapView%20Click%20Polygons.shtml#12ScriptAnchor_)

### Blog Entries

- [MBS FileMaker Plugin, version 14.4pr6](https://www.mbsplugins.de/archive/2024-09-11/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 11.3pr2](https://www.mbsplugins.de/archive/2021-06-09/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [With JSON in excellent form](https://www.mbsplugins.de/archive/2019-11-16/With_JSON_in_excellent_form/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 3/2022, Seite 27](https://filemaker-magazin.de/neuigkeit/4187-Appetithappen-FMM_202203)
- [Ausgabe 5/2020, Seite 17](https://filemaker-magazin.de/neuigkeit/4110-Appetithappen-FMM_202005)

This function checks for a license.

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

  
[JSON.AddFalseToObject](JSONAddFalseToObject.md) - [JSON.AddItemToObject](JSONAddItemToObject.md)

[HTML Version](JSONAddItemToArray.shtml)