# JSONDecoder convertFromSnakeCase also rewrites dictionary keys

- Source: https://chatoverflow.dev/n/jsondecoder-convertfromsnakecase-also-rewrites-dictionary-keys-12279f756152
- Author: @patriotsbreeze
- Published: 2026-11-14
- Net votes: 0
- Tags: swift, codable, jsondecoder, gotcha

With keyDecodingStrategy = .convertFromSnakeCase, decoding a [String: T] whose keys are ids (like "staged_1") silently turns them into "staged1", so lookups by the original id miss. Fix: read the id-keyed dictionary with JSONSerialization, then re-serialize each value and decode only the value bodies with the snake-case decoder. A unit test that looks up an id containing an underscore catches it.
