Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Tcl) Build JSON with Mixture of Arrays and ObjectsAnother example showing how to build JSON containing a mixture of arrays and objects.
load ./chilkat.dll # We want to build the following JSON: # { # "accountEnabled": true, # "assignedLicenses": [ # { # "disabledPlans": [ "bea13e0c-3828-4daa-a392-28af7ff61a0f" ], # "skuId": "skuId-value" # } # ], # "assignedPlans": [ # { # "assignedDateTime": "datetime-value", # "capabilityStatus": "capabilityStatus-value", # "service": "service-value", # "servicePlanId": "bea13e0c-3828-4daa-a392-28af7ff61a0f" # } # ], # "businessPhones": [ # "businessPhones-value" # ], # "city": "city-value", # "companyName": "companyName-value" # } set json [new_CkJsonObject] CkJsonObject_UpdateBool $json "accountEnabled" 1 CkJsonObject_put_I $json 0 CkJsonObject_UpdateString $json "assignedLicenses[i].disabledPlans[0]" "bea13e0c-3828-4daa-a392-28af7ff61a0f" CkJsonObject_UpdateString $json "assignedLicenses[i].skuId" "skuId-value" CkJsonObject_UpdateString $json "assignedPlans[i].assignedDateTime" "datetime-value" CkJsonObject_UpdateString $json "assignedPlans[i].capabilityStatus" "capabilityStatus-value" CkJsonObject_UpdateString $json "assignedPlans[i].service" "service-value" CkJsonObject_UpdateString $json "assignedPlans[i].servicePlanId" "bea13e0c-3828-4daa-a392-28af7ff61a0f" CkJsonObject_UpdateString $json "businessPhones[i]" "businessPhones-value" CkJsonObject_UpdateString $json "city" "city-value" CkJsonObject_UpdateString $json "companyName" "companyName-value" CkJsonObject_put_EmitCompact $json 0 puts [CkJsonObject_emit $json] # Output: # { # "accountEnabled": true, # "assignedLicenses": [ # { # "disabledPlans": [ # "bea13e0c-3828-4daa-a392-28af7ff61a0f" # ], # "skuId": "skuId-value" # } # ], # "assignedPlans": [ # { # "assignedDateTime": "datetime-value", # "capabilityStatus": "capabilityStatus-value", # "service": "service-value", # "servicePlanId": "bea13e0c-3828-4daa-a392-28af7ff61a0f" # } # ], # "businessPhones": [ # "businessPhones-value" # ], # "city": "city-value", # "companyName": "companyName-value" # } delete_CkJsonObject $json |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.