---
title: JSONSerialization
framework: foundation
role: symbol
role_heading: Class
path: foundation/jsonserialization
---

# JSONSerialization

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

## Declaration

```swift
class JSONSerialization
```

## Overview

Overview You use the JSONSerialization class to convert JSON to Foundation objects and convert Foundation objects to JSON. To convert a Foundation object to JSON, the object must have the following properties: The top level object is an NSArray or NSDictionary, unless you set the fragmentsAllowed option. All objects are instances of NSString, NSNumber, NSArray, NSDictionary, or NSNull. All dictionary keys are instances of NSString. Numbers are neither NaN nor infinity. Other rules may apply. Calling isValidJSONObject(_:) or attempting a conversion are the definitive ways to tell if the JSONSerialization class can convert given object to JSON data. note: On iOS 7 and later and macOS 10.9 and later, JSONSerialization is thread safe.

## Topics

### Creating a JSON Object

- [jsonObject(with:options:)](foundation/jsonserialization/jsonobject(with:options:)-8demi.md)
- [jsonObject(with:options:)](foundation/jsonserialization/jsonobject(with:options:)-3afap.md)
- [JSONSerialization.ReadingOptions](foundation/jsonserialization/readingoptions.md)

### Creating JSON Data

- [data(withJSONObject:options:)](foundation/jsonserialization/data(withjsonobject:options:).md)
- [writeJSONObject(_:to:options:error:)](foundation/jsonserialization/writejsonobject(_:to:options:error:).md)
- [JSONSerialization.WritingOptions](foundation/jsonserialization/writingoptions.md)
- [isValidJSONObject(_:)](foundation/jsonserialization/isvalidjsonobject(_:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### JSON

- [Using JSON with custom types](foundation/using-json-with-custom-types.md)
- [JSONEncoder](foundation/jsonencoder.md)
- [JSONDecoder](foundation/jsondecoder.md)
