Class

JSONDecoder

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

Topics

Creating Decoders

init()

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 used to decode floating-point numbers with exceptional values.

See Also

JSON

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.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software