The JsonStructNew function creates a new JSON object ({}) or array ([]).
You can create up to 1,000 JSON objects per thread, and they are all automatically reset if they are exceeded.
object @JsonStructNew(string type);
Parameters
string type :
"{}" - Create a JSON object
"[]" - Generate JSON arrays
Return Values
The ID (string) of the JSON object generated on success, with the format "JsonStruct_{Number}" (e.g., "JsonStruct_1")
Return an empty string on failure
Example 1)
// 1. JSON Object Creation
string jsonObj = @JsonStructNew("{}");
// 2. Set properties
@JsonSet(jsonObj, "name", "John", "string");
@JsonSet(jsonObj, "age", 30,
"int");
@JsonSet(jsonObj, "isActive", true, "bool");
// 3. Create nested objects
string addressObj = @JsonStructNew("{}");
@JsonSet(addressObj, "city", "Seoul",
"string");
@JsonSet(addressObj, "zipcode", "12345", "string");
// 4. Add nested objects
@JsonSet(jsonObj, "address", addressObj);
// 5. Create an array
string phoneArray = @JsonStructNew("[]");
@JsonAppend(phoneArray,
"010-1234-5678", "string");
@JsonAppend(phoneArray, "02-123-4567", "string");
// 6. Add an array
@JsonSet(jsonObj, "phoneNumbers", phoneArray);
// 7. Convert to JSON String
string jsonString = @JsonToString(jsonObj);
@MessageBox(jsonString, "jsonString", MB_OK);
// 8. Memory
Cleanup
@JsonClear(jsonObj);
@JsonClear(addressObj);
@JsonClear(phoneArray);
Example 2)
| //Creating an Order Object string orderObj = @JsonStructNew("{}"); object t = @DateTimeNow(); string dateTimeString = @DateTimeGetString(t); @JsonSet(orderObj, "orderId", "ORD-2025-001", "string"); @JsonSet(orderObj, "orderDate", dateTimeString, "datetime:yyyy-MM-dd HH:mm:ss"); @JsonSet(orderObj, "totalAmount", 250000, "int"); // Customer Information Objects string customerObj = @JsonStructNew("{}"); @JsonSet(customerObj, "id", "CUST001", "string"); @JsonSet(customerObj, "name", "John", "string"); @JsonSet(customerObj, "email", "John@example.com", "string"); @JsonSet(orderObj, "customer", customerObj); // Destination Information Object string shippingObj = @JsonStructNew("{}"); @JsonSet(shippingObj, "address", "124, Sagimakgol-ro, Jungwon-gu, Seongnam-si,", "string"); @JsonSet(shippingObj, "contactPhone", "010-1234-5678", "string"); @JsonSet(orderObj, "shipping", shippingObj); // Order Item Array string itemsArray = @JsonStructNew("[]"); // First item string item1 = @JsonStructNew("{}"); @JsonSet(item1, "productId", "P001", "string"); @JsonSet(item1, "name", "SmartPhone", "string"); @JsonSet(item1, "quantity", 1, "int"); @JsonSet(item1, "price", 150000, "int"); @JsonAppend(itemsArray, item1); // Second item string item2 = @JsonStructNew("{}"); @JsonSet(item2, "productId", "P002", "string"); @JsonSet(item2, "name", "Power bank", "string"); @JsonSet(item2, "quantity", 2, "int"); @JsonSet(item2, "price", 50000, "int"); @JsonAppend(itemsArray, item2); // Add an array of items @JsonSet(orderObj, "items", itemsArray); // Generate the final JSON string¼º string finalJson = @JsonToString(orderObj); // Clean up resources @JsonClear(orderObj); @JsonClear(customerObj); @JsonClear(shippingObj); @JsonClear(itemsArray); @JsonClear(item1); @JsonClear(item2); |
Final JSON String { "orderId": "ORD-2025-001", "orderDate": "2025-03-19 14:30:45", "totalAmount": 250000, "customer": { "id": "CUST001", "name": "John", "email": "John@example.com" }, "shipping": { "address": "124, Sagimakgol-ro, Jungwon-gu, Seongnam-si,", "contactPhone": "010-1234-5678" }, "items": [ { "productId": "P001", "name": "SmartPhone", "quantity": 1, "price": 150000 }, { "productId": "P002", "name": "Power bank", "quantity": 2, "price": 50000 } ] } |
Version information
Supported Version: 10.3.6.25 or later
Related Helps)
JsonTemplateReplacePlaceholder