Class
JSONDecoder
iOS 8.0+
iPadOS 8.0+
Mac Catalyst 8.0+
macOS 10.10+
tvOS 9.0+
watchOS 2.0+
An object that decodes instances of a data type from JSON objects.
class JSONDecoder
Topics
Initializers
init()Creates a new, reusable JSON decoder with the default formatting settings and decoding strategies.
Instance Properties
var allowsJSON5: BoolSpecifies that decoding supports the JSON5 syntax.var assumesTopLevelDictionary: BoolSpecifies that decoding assumes the top level of the JSON data is a dictionary, even if it doesn’t begin and end with braces.var dataDecodingStrategy: JSONDecoder.DataDecodingStrategyThe strategy that a decoder uses to decode raw data.var dateDecodingStrategy: JSONDecoder.DateDecodingStrategyThe strategy used when decoding dates from part of a JSON object.var keyDecodingStrategy: JSONDecoder.KeyDecodingStrategyA value that determines how to decode a type’s coding keys from JSON keys.var nonConformingFloatDecodingStrategy: JSONDecoder.NonConformingFloatDecodingStrategyThe strategy used by a decoder when it encounters exceptional floating-point values.var userInfo: [CodingUserInfoKey : any Sendable]A dictionary you use to customize the decoding process by providing contextual information.
Instance Methods
func decode<T>(T.Type, from: Data) throws -> TReturns a value of the type you specify, decoded from a JSON object.func decode(_:from:configuration:)
Enumerations
enum DataDecodingStrategyThe strategies for decoding raw data.enum DateDecodingStrategyThe strategies available for formatting dates when decoding them from JSON.enum KeyDecodingStrategyThe values that determine how to decode a type’s coding keys from JSON keys.enum NonConformingFloatDecodingStrategyThe strategies for encoding nonconforming floating-point numbers, also known as IEEE 754 exceptional values.
Relationships
Conforms To
ContentDecoderJWTJSONDecoderSwift.CopyableSwift.EscapableSwift.SendableSwift.SendableMetatype