The JsonSet function adds key-value pairs to a JSON object.
int @JsonSet(string objectId, string key, object value);
int @JsonSet(string objectId, string key, object value, string dataType);
Parameters
string objectId : Target JSON object ID
string key : Key Name
object value : JSON object ID to set
string dataType : The data type of the value, "string" when not filled in
"string" : string value
"int", "long" : integer value
"float", "double", "decimal" : real value
"bool" : boolean value
"datetime" : datetime value
"null" : null
Return Values
1 : Success
0 : Failure
Example 1)
string jsonObject = @JsonStructNew("{}");
// Different types
of data settings
@JsonSet(jsonObject, "name", "Product Name", "string");
@JsonSet(jsonObject, "price",
99000, "int");
@JsonSet(jsonObject, "weight", 2.5, "double");
@JsonSet(jsonObject, "available", true, "bool");
@JsonSet(jsonObject,
"manufactureDate", "2025-01-15", "datetime:yyyy-MM-dd");
//
Result :
{"name":"Product Name","price":99000,"weight":2.5,"available":true,"manufactureDate":"2025-01-15"}
string result = @JsonToString(jsonObject);
Example 2)
// 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);
Version information
Supported Version: 10.3.6.25 or later
Related Helps)
JsonTemplateReplacePlaceholder