Sample code for 30+ languages & platforms
PowerBuilder

JSON PathPrefix Example

Demonstrates the JSON object's PathPrefix property.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Json
string ls_City

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

loo_Json.PathPrefix = "company.billing."

loo_Json.UpdateString("company_name","TechNova Solutions Inc.")
loo_Json.UpdateString("address_line_1","123 Innovation Drive")
loo_Json.UpdateString("address_line_2","Suite 450")
loo_Json.UpdateString("city","Seattle")
loo_Json.UpdateString("state_province","WA")
loo_Json.UpdateString("postal_code","98101")
loo_Json.UpdateString("country","USA")

loo_Json.EmitCompact = 0

Write-Debug loo_Json.Emit()

// Result:

// {
//   "company": {
//     "billing": {
//       "company_name": "TechNova Solutions Inc.",
//       "address_line_1": "123 Innovation Drive",
//       "address_line_2": "Suite 450",
//       "city": "Seattle",
//       "state_province": "WA",
//       "postal_code": "98101",
//       "country": "USA"
//     }
//   }
// }

ls_City = loo_Json.StringOf("city")
Write-Debug "city = " + ls_City


destroy loo_Json