package mantra.rest

JsonSerializer

CLASS public class

Utility class for building structured JSON values and serializing object trees into standard JSON strings.

🏗️ Constructor Summary

Constructor Signature
class JsonSerializer

⚙️ Method Summary

Modifier & Return Type Method Signature Description
String static def serialize(value: Object) Serializes a primitive, list, or JsonObject tree to a valid JSON string.
String static def array(items: List) Serializes a list of items into a JSON array string.

🔍 Detailed Method Specifications

static def serialize(value: Object) -> String
Serializes a primitive, list, or JsonObject tree to a valid JSON string.
static def array(items: List) -> String
Serializes a list of items into a JSON array string.

💡 Example Usage

json_serializer_example.mantra
let obj = JsonObject()
    .field("name", JsonValue.Str("Alice"))
    .field("age", JsonValue.Number(30))
    .field("active", JsonValue.Bool(True))

let json_str = obj.to_json()
print(json_str)  # {"name":"Alice","age":30,"active":true}