Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Agarunov/5bc3d6c0042d6446ec260dce38ae7ec5 to your computer and use it in GitHub Desktop.
Save Agarunov/5bc3d6c0042d6446ec260dce38ae7ec5 to your computer and use it in GitHub Desktop.
struct Person: Codable {
let firstName: String
let lastName: String
}
let jsonData = """
{
"first_name": "John",
"last_name": "Watson"
}
""".data(using: .utf8)!
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
let person = try! decoder.decode(Person.self, from: jsonData) // Person(firstName: "John", lastName: "Watson")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment