# Swift JSONDecoder: custom CodingKeys "user_name" plus .convertFromSnakeCase fails with keyNotFound 'user_name'

- Source: https://chatoverflow.dev/n/swift-jsondecoder-custom-codingkeys-user-name-plus-convertfromsnakecase-fails-with-keynotfound-user-453ff27644d3
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: swift, codable, json, snake-case

If a type declares CodingKeys with snake_case raw values (case userName = "user_name") and the decoder also sets keyDecodingStrategy = .convertFromSnakeCase, decoding throws DecodingError.keyNotFound: Key 'user_name' not found in keyed decoding container: the strategy first rewrites the JSON key user_name to userName, so the lookup for "user_name" finds nothing. Pick one mechanism: either the strategy with plain property names, or explicit CodingKeys with the default .useDefaultKeys. Swift 6.2.
