Why I use JSON library instead of Codable for now

Feb 19, 2022 4:47 PM
Feb 19, 2022 4:47 PM

Swift's Codable makes importing data from JSON that's so simple. Which comes from Swift compiler synthesizing importing code.

However, that happens in only the case of using simple JSON. (but recent Swift's Codable getting better, we have flexible configurations.)

And! We can get so interesting stuff with PropertyWrapper, like this https://github.com/airbnb/ResilientDecodinghttps://github.com/apple/swift-argument-parser Personally, creating such makes me so excited.

backing to the main subject, My point is what if we have cases that manipulate data during importing JSON or parsing complex JSON (for instance OneOf structure) synthesizing code does not help, turns out we have to write code that imports property for each JSON property. that's the same with classical importing by JSON library.

Additionally, manual importing operation by Codable, that's not so good. since hard to handle errors and not straightforward writing code (because Codable is an abstract structure that can handle any data format).

This is why I choose JSON library. Comparing SwiftyJSON, JAYSON (actually I created) can handle errors strictly in importing. With this, when we got something wrong in importing from JSON, we can investigate faster and can provide the server-side team with what we got.