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


@interface NSJSONSerialization : NSObject


You use the NSJSONSerialization 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.


Creating a JSON Object

+ JSONObjectWithData:options:error:

Returns a Foundation object from given JSON data.

+ JSONObjectWithStream:options:error:

Returns a Foundation object from JSON data in a given stream.

Creating JSON Data

+ dataWithJSONObject:options:error:

Returns JSON data from a Foundation object.

+ writeJSONObject:toStream:options:error:

Writes a given JSON object to a stream.

+ isValidJSONObject:

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



Options used when creating Foundation objects from JSON data—see JSONObjectWithData:options:error: and JSONObjectWithStream:options:error:.


Options for writing JSON data.


Inherits From

See Also


Using JSON with Custom Types

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

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