Skip to content

Enumeration

JSONEncoder.KeyEncodingStrategy

iOS 8.0+ iPadOS 8.0+ Mac Catalyst 8.0+ macOS 10.10+ tvOS 9.0+ watchOS 2.0+
The values that determine how to encode a type’s coding keys as JSON keys.
enum KeyEncodingStrategy

Overview

Note

Key encoding strategies other than JSONEncoder.KeyEncodingStrategy.useDefaultKeys may have a noticeable performance cost because those strategies may inspect and transform each key.

Topics

Enumeration Cases

  • case convertToSnakeCase
    Convert from “camelCaseKeys” to “snake_case_keys” before writing a key to JSON payload.
  • case custom(([any CodingKey]) -> any CodingKey)
    Provide a custom conversion to the key in the encoded JSON from the keys specified by the encoded types. The full path to the current encoding position is provided for context (in case you need to locate this key within the payload). The returned key is used in place of the last component in the coding path before encoding. If the result of the conversion is a duplicate key, then only one value will be present in the result.
  • case useDefaultKeys
    Use the keys specified by each type. This is the default strategy.

Relationships

Conforms To

  • Swift.Sendable
  • Swift.SendableMetatype