Blitz3D+ Command Reference

CreateJsonArray ( )

Parameters

None.

Description

Creates an owned empty JSON array.

An array is the ordered list of the JSON world - an inventory, a quest log, a high-score table. It starts empty; grow it with JsonArrayAppend and JsonArrayInsert, read elements with JsonArrayGet, and count them with JsonCount. Elements keep their order through save, load and copy.

Elements can be any JSON kind, including other arrays and objects, nested up to 128 levels. All the array mutators copy their input value, so free each temporary element handle right after adding it.

The returned handle is owned by you: release it with FreeJson. Freeing the array releases everything inside it - but copies you fetched earlier with JsonArrayGet stay valid, because they are independent.

For the full rules, see the Application Data language reference.

Requires Extended mode.

See also: JsonArrayAppend, JsonArrayGet, JsonCount, CreateJsonObject, FreeJson.

Example

; CreateJsonArray Example
; -----------------------
; Requires Extended mode.

; CreateJsonArray makes an empty JSON array - here, a hero's inventory
inventory=CreateJsonArray()
Print "New array, elements: "+JsonCount(inventory)

; Append some starting equipment (append copies the value,
; so each temporary handle is freed right after use)
v=CreateJsonString("sword")
JsonArrayAppend inventory,v
FreeJson v

v=CreateJsonString("shield")
JsonArrayAppend inventory,v
FreeJson v

v=CreateJsonString("potion")
JsonArrayAppend inventory,v
FreeJson v

Print "After looting, elements: "+JsonCount(inventory)
Print ""
Print "Inventory as JSON: "+JsonStringify(inventory,0)

FreeJson inventory

Print ""
Print "Press any key to close the example"
WaitKey

End

Index