JSON.ArraySlice
---------------

Slices a JSON array.

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

MBS( "JSON.ArraySlice"; JSON { ; Start; end; AsReference } ) 

**MBS**( **"JSON.ArraySlice";** /\* Slices a JSON array. \*/  
**$JSON**; /\* A JSON text or reference.e.g. \[1,2,3\] \*/   
**$Start**; /\* Optional; Start position. Default is 0.  
Negative numbers select from the end of the array.e.g. 0 \*/   
**$end**; /\* Optional; End position. Default is last element.  
Negative numbers select from the end of the array.  
If end is bigger than the array size, we stop at the end of the array. \*/   
**$AsReference**) /\* Optional; Whether to return a reference number (1) instead of the JSON text (0).  
Default is 0 for JSON text.e.g. 0 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| JSON | A JSON text or reference. | \[1,2,3\] |  |
| Start | Start position. Default is 0.   Negative numbers select from the end of the array. | 0 | Optional |
| end | End position. Default is last element.   Negative numbers select from the end of the array.   If end is bigger than the array size, we stop at the end of the array. |  | Optional |
| AsReference | Whether to return a reference number (1) instead of the JSON text (0).   Default is 0 for JSON text. | 0 | Optional |

### Result

Returns OK or error.

### Description

Slices a JSON array.  
The slice() method returns selected elements in an array, as a new array. The elements are picked from a given start, up to a (not inclusive) given end. It does not change the original array.  
### Examples

Slice an array:

 MBS ("JSON.ArraySlice"; "\[\\"Banana\\", \\"Orange\\", \\"Lemon\\", \\"Apple\\", \\"Mango\\"\]"; 1; 2)  
<small>  
Example result:   
\["Orange" , "Lemon" \] </small>Slice with negative indexes:

 MBS ("JSON.ArraySlice"; "\[\\"Banana\\", \\"Orange\\", \\"Lemon\\", \\"Apple\\", \\"Mango\\"\]"; -3; -1)  
<small>  
Example result:   
\["Lemon" , "Apple" \] </small>Slice with out of bounds range:

 MBS ("JSON.ArraySlice"; "\[\\"Banana\\", \\"Orange\\", \\"Lemon\\", \\"Apple\\", \\"Mango\\"\]"; -10; 10; 0)  
<small>  
Example result:   
\["Banana" , "Orange" , "Lemon" , "Apple" , "Mango" \] </small>### Blog Entries

- [New in MBS FileMaker Plugin 15.0](https://www.mbsplugins.de/archive/2025-01-21/New_in_MBS_FileMaker_Plugin_15/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 8th January 2025 , last changed 8th January 2025

  
[JSON.AddValueToObject](JSONAddValueToObject.md) - [JSON.ClearVariables](JSONClearVariables.md)

[HTML Version](JSONArraySlice.shtml)