<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 8.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/JSONDecoder/KeyDecodingStrategy-swift.enum/convertFromSnakeCase",
  "metadataVersion" : "0.1.0",
  "role" : "Case",
  "symbol" : {
    "kind" : "Case",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation11JSONDecoderC19KeyDecodingStrategyO20convertFromSnakeCaseyA2EmF"
  },
  "title" : "JSONDecoder.KeyDecodingStrategy.convertFromSnakeCase"
}
-->

# JSONDecoder.KeyDecodingStrategy.convertFromSnakeCase

A key decoding strategy that converts snake-case keys to camel-case keys.

```
case convertFromSnakeCase
```

## Discussion

Snake-case and camel-case are two common approaches for combining words when naming parts of an API. The Swift [API Design Guidelines](https://swift.org/documentation/api-design-guidelines/#general-conventions) recommend using camel-case names. Some JSON APIs adopt snake-case; use this strategy when you encounter such an API.

This strategy uses [`uppercaseLetters`](/documentation/Foundation/CharacterSet/uppercaseLetters) and [`lowercaseLetters`](/documentation/Foundation/CharacterSet/lowercaseLetters) to determine the boundaries between words, and the [`system`](/documentation/Foundation/NSLocale/system) locale when capitalizing letters.

This strategy follows these steps to convert JSON keys to camel-case:

1. Capitalize each word that follows an underscore.
2. Remove all underscores that aren’t at the very start or end of the string.
3. Combine the words into a single string.

The following examples show the result of applying this strategy:

- `fee_fi_fo_fum`: Converts to: `feeFiFoFum`
- `feeFiFoFum`: Converts to: `feeFiFoFum`
- `base_uri`: Converts to: `baseUri`

> Note:
> The ``doc://com.apple.foundation/documentation/Foundation/JSONDecoder/KeyDecodingStrategy-swift.enum/convertFromSnakeCase`` strategy can’t infer capitalization for acronyms or initialisms such as WYSIWYG or URI. The example above shows how the automatic conversion differs from the conversion you might expect: `baseURI`. To decode such a key with the correct capitalization, define a custom `CodingKeys` enumeration, as described in <doc://com.apple.foundation/documentation/Foundation/encoding-and-decoding-custom-types>.

The example below shows how properties on the `OlympicEventResult` structure convert from snake-case when decoded as keys in a JSON object.

```swift
struct OlympicEventResult: Codable {
    var goldWinner: String
    var silverWinner: String
    var bronzeWinner: String
}

let json = """
{
    "silver_winner": "Sound",
    "gold_winner": "Light",
    "bronze_winner": "Unladen Swallow"
}
""".data(using: .utf8)!

let decoder = JSONDecoder()
let decodeAndPrint = { print(try! decoder.decode(OlympicEventResult.self, from: json)) }

decoder.keyDecodingStrategy = .convertFromSnakeCase
decodeAndPrint()

// Prints: "OlympicEventResult(goldWinner: "Light", silverWinner: "Sound", bronzeWinner: "Unladen Swallow")"
```

## See Also

[`JSONEncoder.KeyEncodingStrategy.convertToSnakeCase`](/documentation/Foundation/JSONEncoder/KeyEncodingStrategy-swift.enum/convertToSnakeCase)

A key encoding strategy that converts camel-case keys to snake-case keys.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)