Topics   All   MacOS (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Deprecated   Guides   Examples   Videos
New in version: 12.2   12.3   12.4   12.5   13.0   13.1   13.2   13.3   13.4   13.5    Statistic    FMM    Blog  

JSON.DeleteItemFromArray

Deletes an item from an array.

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

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"; 1; 2; 3);
      r = MBS( "JSON.DeleteItemFromArray"; j; MBS( "JSON.GetArraySize"; 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"; input);
// loop over items backwards
c = MBS("JSON.GetArraySize"; j);
r = While ( [ i = c-1 ] ; i >= 0 ; [
    // query a value and if it doesn't match
    r = If( MBS( "JSON.GetPathItem"; j; i & ¶ & "land"; 1 ) <> "CH" ;
        // remove an item
        MBS( "JSON.DeleteItemFromArray"; j; i ); ""); i = i - 1 ] ; "" );
// Format and return JSON
r = MBS("JSON.Format"; j);
x = MBS("JSON.Release"; j)
]; r)

See also

Blog Entries

This function checks for a license.

Created 18th August 2014, last changed 5th November 2020


JSON.CreateValue - JSON.DeleteItemFromObject

💬 Ask a question or report a problem