Sample code for 30+ languages & platforms
PowerBuilder

Create a JSON Array Containing an Object

See more JSON Examples

Creates a top-level JSON array containing an object.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
oleobject loo_JArray
oleobject loo_Json

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

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_JArray.AddObjectAt2(0,loo_Json)

loo_Json.UpdateString("groupId","")
loo_Json.UpdateString("sku","")
loo_Json.UpdateString("title","")
loo_Json.UpdateString("barcode","")
loo_Json.UpdateString("category","")
loo_Json.UpdateString("description","")
loo_Json.UpdateString("images[0]","url1")
loo_Json.UpdateString("images[1]","url...")
loo_Json.UpdateString("isbn","")
loo_Json.UpdateString("link","")
loo_Json.UpdateString("linkLomadee","")
loo_Json.UpdateString("prices[0].type","")
loo_Json.UpdateNumber("prices[0].price","0")
loo_Json.UpdateNumber("prices[0].priceLomadee","0")
loo_Json.UpdateNumber("prices[0].priceCpa","0")
loo_Json.UpdateNumber("prices[0].installment","0")
loo_Json.UpdateNumber("prices[0].installmentValue","0")
loo_Json.UpdateString("productAttributes.~"Atributo 1~"","Valor 1")
loo_Json.UpdateString("productAttributes.~"Atributo ...~"","Valor ...")
loo_Json.UpdateString("technicalSpecification.~"Especificação 1~"","Valor")
loo_Json.UpdateString("technicalSpecification.~"Especificação ...~"","Valor ...")
loo_Json.UpdateNumber("quantity","0")
loo_Json.UpdateNumber("sizeHeight","0")
loo_Json.UpdateNumber("sizeLength","0")
loo_Json.UpdateNumber("sizeWidth","0")
loo_Json.UpdateNumber("weightValue","0")
loo_Json.UpdateNumber("declaredPrice","0")
loo_Json.UpdateNumber("handlingTimeDays","0")
loo_Json.UpdateBool("marketplace",0)
loo_Json.UpdateString("marketplaceName","")

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

// The output of this program is:

// [
//   {
//     "groupId": "",
//     "sku": "",
//     "title": "",
//     "barcode": "",
//     "category": "",
//     "description": "",
//     "images": [
//       "url1",
//       "url..."
//     ],
//     "isbn": "",
//     "link": "",
//     "linkLomadee": "",
//     "prices": [
//       {
//         "type": "",
//         "price": 0,
//         "priceLomadee": 0,
//         "priceCpa": 0,
//         "installment": 0,
//         "installmentValue": 0
//       }
//     ],
//     "productAttributes": {
//       "Atributo 1": "Valor 1",
//       "Atributo ...": "Valor ..."
//     },
//     "technicalSpecification": {
//       "Especificação 1": "Valor",
//       "Especificação ...": "Valor ..."
//     },
//     "quantity": 0,
//     "sizeHeight": 0,
//     "sizeLength": 0,
//     "sizeWidth": 0,
//     "weightValue": 0,
//     "declaredPrice": 0,
//     "handlingTimeDays": 0,
//     "marketplace": false,
//     "marketplaceName": ""
//   }
// ]


destroy loo_JArray
destroy loo_Json