One Logo Pool Ball
Foundation · IOS API REFERENCE

JSONDecoder

class · iOS 8.0+ · SDK 27.1

class JSONDecoder

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

Members (16)

get · iOS 15.0+

allowsJSON5

TypeScript
get allowsJSON5(): boolean
Swift declaration
var allowsJSON5: Bool { get set }

Specifies that decoding supports the JSON5 syntax. Defaults to `false`.

set · iOS 15.0+

allowsJSON5

TypeScript
set allowsJSON5(value: boolean)
Swift declaration
var allowsJSON5: Bool { get set }

Specifies that decoding supports the JSON5 syntax. Defaults to `false`.

get · iOS 8.0+

keyDecodingStrategy

TypeScript
get keyDecodingStrategy(): JSONDecoder_KeyDecodingStrategy
Swift declaration
var keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy { get set }

A value that determines how to decode a type's coding keys from JSON keys. Defaults to `.useDefaultKeys`.

set · iOS 8.0+

keyDecodingStrategy

TypeScript
set keyDecodingStrategy(value: JSONDecoder_KeyDecodingStrategy)
Swift declaration
var keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy { get set }

A value that determines how to decode a type's coding keys from JSON keys. Defaults to `.useDefaultKeys`.

get · iOS 8.0+

dataDecodingStrategy

TypeScript
get dataDecodingStrategy(): JSONDecoder_DataDecodingStrategy
Swift declaration
var dataDecodingStrategy: JSONDecoder.DataDecodingStrategy { get set }

The strategy that a decoder uses to decode raw data. Defaults to `.base64`.

set · iOS 8.0+

dataDecodingStrategy

TypeScript
set dataDecodingStrategy(value: JSONDecoder_DataDecodingStrategy)
Swift declaration
var dataDecodingStrategy: JSONDecoder.DataDecodingStrategy { get set }

The strategy that a decoder uses to decode raw data. Defaults to `.base64`.

get · iOS 8.0+

dateDecodingStrategy

TypeScript
get dateDecodingStrategy(): JSONDecoder_DateDecodingStrategy
Swift declaration
var dateDecodingStrategy: JSONDecoder.DateDecodingStrategy { get set }

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

set · iOS 8.0+

dateDecodingStrategy

TypeScript
set dateDecodingStrategy(value: JSONDecoder_DateDecodingStrategy)
Swift declaration
var dateDecodingStrategy: JSONDecoder.DateDecodingStrategy { get set }

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

get · iOS 15.0+

assumesTopLevelDictionary

TypeScript
get assumesTopLevelDictionary(): boolean
Swift declaration
var assumesTopLevelDictionary: Bool { get set }

Specifies that decoding assumes the top level of the JSON data is a dictionary, even if it doesn't begin and end with braces. Defaults to `false`. Compatible with both JSON5 and non-JSON5 mode.

set · iOS 15.0+

assumesTopLevelDictionary

TypeScript
set assumesTopLevelDictionary(value: boolean)
Swift declaration
var assumesTopLevelDictionary: Bool { get set }

Specifies that decoding assumes the top level of the JSON data is a dictionary, even if it doesn't begin and end with braces. Defaults to `false`. Compatible with both JSON5 and non-JSON5 mode.

get · iOS 8.0+

nonConformingFloatDecodingStrategy

TypeScript
get nonConformingFloatDecodingStrategy(): JSONDecoder_NonConformingFloatDecodingStrategy
Swift declaration
var nonConformingFloatDecodingStrategy: JSONDecoder.NonConformingFloatDecodingStrategy { get set }

The strategy used by a decoder when it encounters exceptional floating-point values. Defaults to `.throw`.

set · iOS 8.0+

nonConformingFloatDecodingStrategy

TypeScript
set nonConformingFloatDecodingStrategy(value: JSONDecoder_NonConformingFloatDecodingStrategy)
Swift declaration
var nonConformingFloatDecodingStrategy: JSONDecoder.NonConformingFloatDecodingStrategy { get set }

The strategy used by a decoder when it encounters exceptional floating-point values. Defaults to `.throw`.

method · iOS 8.0+

decode

TypeScript
decode(type: "Bool" | "Int" | "UInt" | "Double" | "Float" | "String" | "CGFloat" | "Date" | "URL" | "Data" | "UUID", data: ArrayBuffer): unknown
Swift declaration
func decode<T>(_ type: T.Type, from data: Data) throws -> T where T : Decodable

Returns a value of the type you specify, decoded from a JSON object. - parameter type: The type of the value to decode. - parameter data: The data to decode from. - returns: A value of the requested type. - throws: `DecodingError.dataCorrupted` if values requested from the payload are corrupted, or if the given data is not valid JSON. - throws: An error if any value throws an error during decoding.

get · iOS 8.0+

userInfo

TypeScript
get userInfo(): NativeMap<SDKHandle, SDKHandle>
Swift declaration
@preconcurrency var userInfo: [CodingUserInfoKey : any Sendable] { get set }

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

set · iOS 8.0+

userInfo

TypeScript
set userInfo(value: NativeMap<SDKHandle, SDKHandle>)
Swift declaration
@preconcurrency var userInfo: [CodingUserInfoKey : any Sendable] { get set }

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

init · iOS 8.0+

init

TypeScript
static init(): JSONDecoder
Swift declaration
init()

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

Skipped declarations

2 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

JSONDecoder.decode(_:from:configuration:)

This declaration needs Swift generic type arguments. (no canonical witness for T.DecodingConfiguration)

JSONDecoder.decode(_:from:configuration:)

Passing a Swift type itself is not supported.

All Foundation types →