Sample code for 30+ languages & platforms
Swift

JSON PathPrefix Example

Demonstrates the JSON object's PathPrefix property.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let json = CkoJsonObject()!

    json.pathPrefix = "company.billing."

    json.updateString(jsonPath: "company_name", value: "TechNova Solutions Inc.")
    json.updateString(jsonPath: "address_line_1", value: "123 Innovation Drive")
    json.updateString(jsonPath: "address_line_2", value: "Suite 450")
    json.updateString(jsonPath: "city", value: "Seattle")
    json.updateString(jsonPath: "state_province", value: "WA")
    json.updateString(jsonPath: "postal_code", value: "98101")
    json.updateString(jsonPath: "country", value: "USA")

    json.emitCompact = false

    print("\(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"
    //     }
    //   }
    // }

    var city: String? = json.string(of: "city")
    print("city = \(city!)")

}