v2026.5.3
All Bundles
Bundle JSON parsing and building library. JsonParser reads JSON strings into a JsonElement tree; JsonBuilder constructs JSON documents using a stack-based API. Compile with -lib json.

JsonBuilder

Stack driven JSON builder

builder := JsonBuilder->New();
money := builder->PushObject();

money->Insert("type", "usd");
money->Insert("amount", "1013");

deposits := JsonElement->New(JsonElement->JsonType->ARRAY);
deposits->Add(115);
deposits->Add(318);
deposits->Add(580);
money->Insert("deposits", deposits);

builder->Pop()->ToString()->PrintLine();

Operations

Add #

Adds a value

method : public : Add(value:String) ~ JsonBuilder

Parameters

NameTypeDescription
valueStringvalue

Return

TypeDescription
JsonBuildertrue if successful, false otherwise

Example

builder := Data.JSON.JsonBuilder->New();
arr := builder->PushArray();
arr->Add("red");
arr->Add("green");
arr->Add("blue");
builder->Pop()->ToString()->PrintLine();

Add #

Adds a value

method : public : Add(value:Int) ~ JsonBuilder

Parameters

NameTypeDescription
valueIntvalue

Return

TypeDescription
JsonBuildertrue if successful, false otherwise

Example

builder := Data.JSON.JsonBuilder->New();
arr := builder->PushArray();
arr->Add(1);
arr->Add(2);
arr->Add(3);
builder->Pop()->ToString()->PrintLine();

Add #

Adds a value

method : public : Add(value:Float) ~ JsonBuilder

Parameters

NameTypeDescription
valueFloatvalue

Return

TypeDescription
JsonBuildertrue if successful, false otherwise

Add #

Adds a value

method : public : Add(value:Bool) ~ JsonBuilder

Parameters

NameTypeDescription
valueBoolvalue

Return

TypeDescription
JsonBuildertrue if successful, false otherwise

Add #

Adds a value

method : public : Add(value:JsonElement) ~ JsonBuilder

Parameters

NameTypeDescription
valueJsonElementvalue

Return

TypeDescription
JsonBuildertrue if successful, false otherwise

Insert #

Insert an element

method : public : Insert(name:String, value:Int) ~ JsonBuilder

Parameters

NameTypeDescription
nameStringelement name
valueIntvalue

Return

TypeDescription
JsonBuildertrue if successful, false otherwise

Example

builder := Data.JSON.JsonBuilder->New();
root := builder->PushObject();
root->Insert("age", 30);
root->Insert("score", 99);
builder->Pop()->ToString()->PrintLine();

Insert #

Insert an element

method : public : Insert(name:String, value:Float) ~ JsonBuilder

Parameters

NameTypeDescription
nameStringelement name
valueFloatvalue

Return

TypeDescription
JsonBuildertrue if successful, false otherwise

Example

builder := Data.JSON.JsonBuilder->New();
root := builder->PushObject();
root->Insert("price", 9.99);
root->Insert("tax", 0.08);
builder->Pop()->ToString()->PrintLine();

Insert #

Insert an element

method : public : Insert(name:String, value:String) ~ JsonBuilder

Parameters

NameTypeDescription
nameStringelement name
valueStringvalue

Return

TypeDescription
JsonBuildertrue if successful, false otherwise

Example

builder := Data.JSON.JsonBuilder->New();
root := builder->PushObject();
root->Insert("name", "Alice");
root->Insert("role", "admin");
builder->Pop()->ToString()->PrintLine();

Insert #

Insert an element

method : public : Insert(name:String, value:Bool) ~ JsonBuilder

Parameters

NameTypeDescription
nameStringelement name
valueBoolvalue

Return

TypeDescription
JsonBuildertrue if successful, false otherwise

Example

builder := Data.JSON.JsonBuilder->New();
root := builder->PushObject();
root->Insert("active", true);
root->Insert("verified", false);
builder->Pop()->ToString()->PrintLine();

Insert #

Insert an element

method : public : Insert(name:String, value:JsonElement) ~ JsonBuilder

Parameters

NameTypeDescription
nameStringelement name
valueJsonElementvalue

Return

TypeDescription
JsonBuildertrue if successful, false otherwise

New # constructor

Constructor

New()

Pop #

Pops a value

method : public : Pop() ~ JsonElement

Return

TypeDescription
JsonElementpopped element

Example

builder := Data.JSON.JsonBuilder->New();
root := builder->PushObject();
root->Insert("x", 1);
json := builder->Pop();
json->ToString()->PrintLine();

PopAll #

Pop all values

method : public : PopAll() ~ JsonElement

Return

TypeDescription
JsonElementlast popped element

Example

builder := Data.JSON.JsonBuilder->New();
builder->PushObject()->Insert("a", 1);
json := builder->PopAll();
json->ToString()->PrintLine();

PushArray #

Pushes an array element on the stack

method : public : PushArray() ~ JsonBuilder

Example

builder := Data.JSON.JsonBuilder->New();
root := builder->PushObject();
arr := root->PushArray("scores");
arr->Add(95);
arr->Add(87);
arr->Add(92);
builder->Pop()->ToString()->PrintLine();

PushObject #

Pushes an object element on the stack

method : public : PushObject() ~ JsonBuilder

Example

builder := Data.JSON.JsonBuilder->New();
root := builder->PushObject();
root->Insert("status", "ok");
root->Insert("count", 3);
builder->Pop()->ToString()->PrintLine();

PushObject #

Pushes an object element on the stack

method : public : PushObject(name:String) ~ JsonBuilder

Parameters

NameTypeDescription
nameStringobject name

Example

builder := Data.JSON.JsonBuilder->New();
root := builder->PushObject();
addr := root->PushObject("address");
addr->Insert("city", "Oakland");
addr->Insert("zip", "94612");
builder->Pop()->ToString()->PrintLine();

Size #

Size of element stack

method : public : Size() ~ Int