KeyedDecodingContainer

extension KeyedDecodingContainer

Extensions for KeyedDecodingContainer to support decoding of dynamic dictionaries and arrays with Sendable values, enabling flexible JSON parsing with unknown structures.

  • Decodes a dictionary with string keys and Sendable values for a given key.

    Throws

    DecodingError if the value cannot be decoded

    Declaration

    Swift

    public func decode(_ type: [String : any Sendable].Type, forKey key: K) throws -> [String : any Sendable]

    Parameters

    type

    The type of dictionary to decode

    key

    The coding key to decode from

    Return Value

    A dictionary with string keys and Sendable values

  • Decodes an array of dictionaries with string keys and Sendable values for a given key.

    Throws

    DecodingError if the value cannot be decoded

    Declaration

    Swift

    public func decode(_ type: [[String : any Sendable]].Type, forKey key: K) throws -> [[String : any Sendable]]

    Parameters

    type

    The type of array of dictionaries to decode

    key

    The coding key to decode from

    Return Value

    An array of dictionaries with string keys and Sendable values

  • Decodes a dictionary with string keys and Sendable values if present for a given key.

    Throws

    DecodingError if the value cannot be decoded

    Declaration

    Swift

    public func decodeIfPresent(_ type: [String : any Sendable].Type, forKey key: K) throws -> [String : any Sendable]?

    Parameters

    type

    The type of dictionary to decode

    key

    The coding key to decode from

    Return Value

    An optional dictionary with string keys and Sendable values, or nil if the key is not present or the value is null

  • Decodes an array of Sendable values for a given key.

    Throws

    DecodingError if the value cannot be decoded

    Declaration

    Swift

    public func decode(_ type: [any Sendable].Type, forKey key: K) throws -> [any Sendable]

    Parameters

    type

    The type of array to decode

    key

    The coding key to decode from

    Return Value

    An array of Sendable values

  • Decodes an array of Sendable values if present for a given key.

    Throws

    DecodingError if the value cannot be decoded

    Declaration

    Swift

    public func decodeIfPresent(_ type: [any Sendable].Type, forKey key: K) throws -> [any Sendable]?

    Parameters

    type

    The type of array to decode

    key

    The coding key to decode from

    Return Value

    An optional array of Sendable values, or nil if the key is not present or the value is null

  • Decodes a dictionary with string keys and Sendable values from the current container.

    This method iterates through all keys in the container and attempts to decode each value as a Bool, String, Int, Double, nested dictionary, or nested array.

    Throws

    DecodingError if the container cannot be processed

    Declaration

    Swift

    public func decode(_ type: [String : any Sendable].Type) throws -> [String : any Sendable]

    Parameters

    type

    The type of dictionary to decode

    Return Value

    A dictionary with string keys and Sendable values containing all successfully decoded values