Sample code for 30+ languages & platforms
PowerBuilder Requires Chilkat v9.5.0.75+

JSON Insert Empty Array or Object

See more JSON Examples

Demonstrates how to use the UpdateNewArray and UpdateNewObject methods to insert an empty array or object.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Json

li_Success = 0

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
if li_rc < 0 then
    destroy loo_Json
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  The following code builds the following JSON, which contains both an empty array and empty object:

//  	{
//  	  "abc": {
//  	    "xyz": [
//  	      {
//  	        "Name": "myName",
//  	        "Description": "description",
//  	        "ScheduleDefinition": "schedule definition",
//  	        "ExceptionScheduleDefinition": "",
//  	        "Attribute": [
//  	        ],
//  	        "SomeEmptyObject": {},
//  	        "token": "token"
//  	      }
//  	    ]
//  	  }
//  	}

loo_Json.UpdateString("abc.xyz[0].Name","myName")
loo_Json.UpdateString("abc.xyz[0].Description","description")
loo_Json.UpdateString("abc.xyz[0].ScheduleDefinition","schedule definition")
loo_Json.UpdateString("abc.xyz[0].ExceptionScheduleDefinition","")
loo_Json.UpdateNewArray("abc.xyz[0].Attribute")
loo_Json.UpdateNewObject("abc.xyz[0].SomeEmptyObject")
loo_Json.UpdateString("abc.xyz[0].token","token")

loo_Json.EmitCompact = 0
Write-Debug loo_Json.Emit()


destroy loo_Json