Previous Topic

Next Topic

JSONSplice - MaxBasic Function

JSONSplice(JSONArray: Object, Start: Number[, DeleteCount: Number, AddItem1: Variant, AddItem2: Variant, ..., AddItemN: Variant]): Object

Takes a JSON Array and adds or removes existing elements. Returns a JSON Array containing the deleted items.

The Start number is the Index at which to start changing the JSON Array. If the Start is negative, the position will begin from the end of the JSON Array.

The DeleteCount number specifies the number if items to be deleted. If the DeleteCount is not included, or is larger than the Array Length minus the Start, then all elements from the start to the end of the array will be deleted. If the DeleteCount is zero or is negative, no elements will be deleted.

If any number of AddItem parameters are included, the AddItem items will be added to the JSON Array.

JSONSplice function has these named arguments:

Parameter

Description

JSON Array

Required. A JSON Array to be modified.

Start

Required. The Index position in the JSON Array to start modifications.

DeleteCount

Optional. The number of items to be deleted from the JSON Array. If the DeleteCount is not included, or is larger than the Array Length minus the Start, then all elements from the start to the end of the array will be deleted. If the DeleteCount is zero or is negative, no elements will be deleted.

AddItem1, AddItem2, ... AddItemN

Optional. Items included as parameters after the DeleteCount parameter will be added to the JSON Array.

The following sample code creates a JSON object based on IN Invoice Data, then creates a JSON Array. It adds three elements to the JSON Array, then uses the JSONSplice function to remove the second Element and return it as JSON2, and add two more elements. It then prints the JSON2 object, and the JSONArray.

Sample code:

Dim datINInvoice as Object

datINInvoice = CreateObject("Accredo.INInvoiceData")

Dim JSON as Object

JSON = BuildJSON(datINInvoice, "CustomerCode;DocumentNo;DocumentID;Line", "Charge;Banking")

Dim JsonArray as Object

JsonArray = JSONCreateArray(JSON, "CustomerCode;DocumentNo")

JSONPush(JsonArray,"ASHENG;1")

JSONPush(JsonArray"BROWN;2")

JSONPush(JsonArray"CHESTER;3")

Dim JSON2 as Object

JSON2 = JSONSplice(JsonArray, 1, 1, "DUGG:4", "FINE:5")

Print JSONStringify(JSON2)

Print JSONStringify(JsonArray)

Sample code:

JSONSplice(JSON1, 2, 1, "NewItem")

This will replace the Item at Position 2 of the JSON Array with "NewItem".

See Also

Web Functions

Book Contents

Book Index