Sample code for 30+ languages & platforms
DataFlex

Example: JsonObject.NewObjectOf method

Demonstrates the NewObjectOf method.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    String sCar
    Handle hoJson
    String sTemp1

    Move False To iSuccess

    Move '{"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}' To sCar

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End

    Get ComUpdateString Of hoJson "test" "abc" To iSuccess

    Get ComNewObjectOf Of hoJson "car" sCar To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoJson To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Set ComEmitCompact Of hoJson To False
    Get ComEmit Of hoJson To sTemp1
    Showln sTemp1

    // 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
    //   }
    // }


End_Procedure