---
title: "jsonObject(with:options:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/jsonserialization/jsonobject(with:options:)-8demi"
---

# jsonObject(with:options:)

Returns a Foundation object from given JSON data.

## Declaration

```swift
class func jsonObject(with data: Data, options opt: JSONSerialization.ReadingOptions = []) throws -> Any
```

## Parameters

- `data`: A data object containing JSON data.
- `opt`: Options for reading the JSON data and creating the Foundation objects. For possible values, see doc://com.apple.foundation/documentation/Foundation/JSONSerialization/ReadingOptions.

## Return Value

Return Value A Foundation object from the JSON data in data, or nil if an error occurs.

## Discussion

Discussion The data must be in one of the 5 supported encodings listed in the JSON specification: UTF-8, UTF-16LE, UTF-16BE, UTF-32LE, UTF-32BE. The data may or may not have a BOM. The most efficient encoding to use for parsing is UTF-8, so if you have a choice in encoding the data passed to this method, use UTF-8. note: In Swift, this method returns a nonoptional result and is marked with the throws keyword to indicate that it throws an error in cases of failure. You call this method in a try expression and handle any errors in the catch clauses of a do statement, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.

## See Also

### Related Documentation

- [data(withJSONObject:options:)](foundation/jsonserialization/data(withjsonobject:options:).md)

### Creating a JSON Object

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