> On Jun 23, 2017, at 9:42 AM, Tony Parker via swift-users 
> <swift-users@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

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to