Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.4.0+

Example: JsonObject.NewObjectOf method

Demonstrates the NewObjectOf method.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL cCar
LOCAL oJson

nSuccess := 0

cCar := '{"make":"Toyota","model":"Camry","year":2022,"color":"silver","engine":{"type":"inline-4","fuel":"gasoline","horsepower":203},"features":["bluetooth","backup camera","adaptive cruise control","lane assist"],"isElectric":false}'

oJson := CreateObject("Chilkat.JsonObject")

oJson:UpdateString("test", "abc")

nSuccess := oJson:NewObjectOf("car", cCar)
IF (nSuccess == 0)
    ? oJson:LastErrorText
    oJson:destroy()
    RETURN
ENDIF

oJson:EmitCompact := 0
? oJson:Emit()

//  Result:

//  {
//    "test": "abc",
//    "car": {
//      "make": "Toyota",
//      "model": "Camry",
//      "year": 2022,
//      "color": "silver",
//      "engine": {
//        "type": "inline-4",
//        "fuel": "gasoline",
//        "horsepower": 203
//      },
//      "features": [
//        "bluetooth",
//        "backup camera",
//        "adaptive cruise control",
//        "lane assist"
//      ],
//      "isElectric": false
//    }
//  }

oJson:destroy()