Class

JSONSerialization

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

Overview

You use the JSONSerialization class to convert JSON to Foundation objects and convert Foundation objects to JSON.

A Foundation object that may be converted to JSON must have the following properties:

Other rules may apply. Calling isValidJSONObject(_:) or attempting a conversion are the definitive ways to tell if a given object can be converted to JSON data.

Topics

Creating a JSON Object

Creating JSON Data

class func isValidJSONObject(Any)

Returns a Boolean value that indicates whether a given object can be converted to JSON data.

Constants

struct JSONSerialization.ReadingOptions

Options used when creating Foundation objects from JSON data—see jsonObject(with:options:) and jsonObject(with:options:).

struct JSONSerialization.WritingOptions

Options for writing JSON data.

Relationships

Inherits From

Conforms To

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 JSONDecoder

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