-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SCLF-0001: JSON Key Strategies #1301
Conversation
let goodbyeCruelWorld: Int | ||
let key: Int | ||
|
||
private enum CodingKeys : CodingKey { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have a raw type of String
, I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup
|
||
Converting from camel case to snake case: | ||
|
||
1. Splits words at the boundary of lower-case to upper-case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I undestand correctly, this implies imageURL
becomes image_URL
, right? Or rather image_url
I guess.
Can we add examples with acronyms to make it clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, right
Lowercases the entire string
so image_url
would be the one, yes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yah, check out the test cases at swiftlang/swift#12779 for some additional examples.
1. Splits words at the boundary of lower-case to upper-case | ||
2. Inserts `_` between words | ||
3. Lowercases the entire string | ||
4. Preserves starting and ending `_`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would we approach numbers?
E.g. what would abc123def
be resolved to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abc123def
- no uppercase characters to split on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abc123Def
would be abc123_def
@parkera do you want to merge this or leave it as a PR? |
I think I'll go ahead and merge this now. |
Add a proposal for handling snake and camel case keys in JSONEncoder.