JsonArrayInsert(json, json, int)
From NWN Lexicon
Jump to navigationJump to search
Returns a modified copy of jArray with jValue inserted at position nIndex.
json JsonArrayInsert(
json jArray,
json jValue,
int nIndex = -1
);
Parameters
- jArray
- The json Array to modify.
- jValue
- The json value to insert.
- nIndex
- The index to insert for a value.
Description
Returns a modified copy of jArray with jValue inserted at position nIndex. All succeeding objects in the array will move by one.
Remarks
By default (-1), inserts objects at the end of the array ("push"). nIndex = 0 inserts at the beginning of the array. Returns a json null value if jArray is not actually an array, with JsonGetError filled in. Returns a json null value if nIndex is not 0 or -1 and out of bounds, with JsonGetError filled in.
Version
This function was added in 1.85.8193.31 of NWN:EE.
Example
void main()
{
json jArray = JsonParse("{[1, 2, 4, 5, 6]}");
// Insert 3 at index 2 (between 2 and 4). We assign the result of the function to the same variable.
jArray = JsonArrayInsert(jArray, JsonInt(3), 2);
WriteTimestampedLogEntry(JsonDump(jArray)); // {[1, 2, 3, 4, 5, 6]}
// Insert 7 at the end of the array
jArray = JsonArrayInsert(jArray, JsonInt(7), -1);
WriteTimestampedLogEntry(JsonDump(jArray)); // {[1, 2, 3, 4, 5, 6, 7]}
// Insert 0 at the start of the array
jArray = JsonArrayInsert(jArray, JsonInt(0), 0);
WriteTimestampedLogEntry(JsonDump(jArray)); // {[0, 1, 2, 3, 4, 5, 6, 7]}
}
See Also
| functions: |