[swift-users] JSON keys survey
brent at architechies.com
Sat Jun 24 06:52:28 CDT 2017
> On Jun 23, 2017, at 9:42 AM, Tony Parker via swift-users <swift-users at swift.org> wrote:
> 1. Does your JSON use snake_case_keys or CamelCase or other?
My internal APIs use snake_case. Several APIs I write against (not necessarily in Swift), like Heroku and Stripe, also use snake_case. The JSON Feed format uses snake_case.
> 2. Is the key type consistent throughout the JSON?
> 3. If JSONEncoder/Decoder converted these, would you have any other need to specify custom keys?
Occasionally, but far less often. For instance, when adapting an API that used Rails conventions, I would still want to translate `created_at` dates to `creationDate`. But that assumes I wanted to use those dates at all—I often ignore them.
If you're considering adding a key transformation strategy to JSONEncoder/Decoder, I strongly encourage you to do so. Case transformation will handle at least 80% of the custom keys, and even when people *do* still need to customize further, case transformation will help them do it more easily. And if you *did* want to provide a `custom` option, it might allow developers to move *all* of their custom JSON key names out of their `Codable` implementations, which would make them easier to use with multiple coders.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-users