An object that decodes instances of a data type from JSON objects.




Creates a new, reusable JSON decoder with the default formatting settings and decoding strategies.

func decode<T>(T.Type, from: Data)

Returns a value of the type you specify, decoded from a JSON object.

Customizing Decoding

var userInfo: [CodingUserInfoKey : Any]

A dictionary you use to customize the decoding process by providing contextual information.

Decoding Dates

var dateDecodingStrategy: JSONDecoder.DateDecodingStrategy

The strategy used when decoding dates from part of a JSON object.

enum JSONDecoder.DateDecodingStrategy

The strategies available for formatting dates when decoding them from JSON.

Decoding Raw Data

var dataDecodingStrategy: JSONDecoder.DataDecodingStrategy

The strategy that a decoder uses to decode raw data.

enum JSONDecoder.DataDecodingStrategy

The strategies for decoding raw data.

Decoding Exceptional Numbers

var nonConformingFloatDecodingStrategy: JSONDecoder.NonConformingFloatDecodingStrategy

The strategy used by a decoder when it encounters exceptional floating-point values.

enum JSONDecoder.NonConformingFloatDecodingStrategy

The strategies for encoding nonconforming floating-point numbers, also known as IEEE 754 exceptional values.

See Also


Using JSON with Custom Types

Demonstrates approaches for encoding and decoding different kinds of JSON in Swift.

class JSONEncoder

An object that encodes instances of a data type as JSON objects.

class JSONSerialization

An object that converts between JSON and the equivalent Foundation objects.