[swift-users] JSON keys survey
Brent Royal-Gordon
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.
I suspect the deciding factor is typically the source language—if your backend is written in Perl, Python, or Ruby, you're probably using snake_case. If it's in JavaScript, Java, C#, or Swift, you're probably using camelCase.
> 2. Is the key type consistent throughout the JSON?
Yes.
> 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.
--
Brent Royal-Gordon
Architechies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170624/94c112e3/attachment.html>
More information about the swift-users
mailing list