JSON.DeleteItemFromArray
------------------------

Deletes an item from 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.DeleteItemFromArray"; JSON; Index ) 

**MBS**( **"JSON.DeleteItemFromArray";** /\* Deletes an item from an array. \*/  
**$JSON**; /\* A JSON text or reference.e.g. \[1,2,3\] \*/   
**$Index**) /\* The zero based index of the value.e.g. 1 \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| JSON | A JSON text or reference. | \[1,2,3\] |
| Index | The zero based index of the value. | 1 |

### Result

Returns JSON code.

### Description

Deletes an item from an array.  
Returns the JSON reference number if called with reference number. Otherwise returns new JSON text.  
### Examples

Create array with numbers and delete last entry:

 Let(  
\[  
 j = MBS ( "[JSON.CreateDoubleArray](JSONCreateDoubleArray.md)"; 1; 2; 3);  
 r = MBS ( "JSON.DeleteItemFromArray"; j; MBS ( "[JSON.GetArraySize](JSONGetArraySize.md)"; j )-1 )  
\];  
r)  
Filter items in JSON:

 Let(\[  
// input may come from caller  
input = "\[{\\"land\\": \\"CH\\"}, {\\"land\\": \\"CH\\"}, {\\"land\\": \\"DE\\"}, {\\"land\\": \\"AT\\"}, {\\"land\\": \\"CH\\"}, {\\"land\\": \\"CH\\"}\]";   
  
// parse the JSON  
j = MBS ("[JSON.Parse](JSONParse.md)"; input);  
// loop over items backwards  
c = MBS ("[JSON.GetArraySize](JSONGetArraySize.md)"; j);  
r = While ( \[ i = c-1 \] ; i &gt;= 0 ; \[   
 // query a value and if it doesn't match  
 r = If( MBS ( "[JSON.GetPathItem](JSONGetPathItem.md)"; j; i &amp; ¶ &amp; "land"; 1 ) &lt;&gt; "CH" ;   
 // remove an item  
 MBS ( "JSON.DeleteItemFromArray"; j; i ); ""); i = i - 1 \] ; "" );  
// Format and return JSON  
r = MBS ("[JSON.Format](JSONFormat.md)"; j);  
x = MBS ("[JSON.Release](JSONRelease.md)"; j)  
\]; r)  
### See also

- [JSON.CreateDoubleArray](JSONCreateDoubleArray.md)
- [JSON.DeleteItemFromObject](JSONDeleteItemFromObject.md)
- [JSON.Format](JSONFormat.md)
- [JSON.GetArraySize](JSONGetArraySize.md)
- [JSON.GetPathItem](JSONGetPathItem.md)
- [JSON.Parse](JSONParse.md)
- [JSON.Release](JSONRelease.md)

### Blog Entries

- [With JSON in excellent form](https://www.mbsplugins.de/archive/2019-11-16/With_JSON_in_excellent_form/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [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 5th November 2020

  
[JSON.CurrentMatchPath](JSONCurrentMatchPath.md) - [JSON.DeleteItemFromObject](JSONDeleteItemFromObject.md)

[HTML Version](JSONDeleteItemFromArray.shtml)