Handle Nested Models and Collections
masterKakaJSON supports deeply nested JSON structures, including arrays, dictionaries, and sets, as long as the nested types also conform to Convertible.
Nested Objects and Collections
struct Book: Convertible {
var name: String = ""
var price: Double = 0.0
}
struct Person: Convertible {
var name: String = ""
var car: Car? // Optional nested object
var books: [Book]? // Array of nested objects
var dogs: [String: Dog]? // Dictionary of nested objects
}Default Values in Nested Models
If a property in your model is initialized with a default value, KakaJSON will preserve that value if the corresponding key is missing from the JSON, rather than overwriting it with a new instance.
struct Person: Convertible {
var name: String = ""
// If 'car' is missing in JSON, this default instance is kept
var car: Car = Car(name: "Bently", price: 106.5)
}