---
title: "decode(_:from:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/jsondecoder/decode(_:from:)"
---

# decode(_:from:)

Returns a value of the type you specify, decoded from a JSON object.

## Declaration

```swift
func decode<T>(_ type: T.Type, from data: Data) throws -> T where T : Decodable
```

## Parameters

- `type`: The type of the value to decode from the supplied JSON object.
- `data`: The JSON object to decode.

## Return Value

Return Value A value of the specified type, if the decoder can parse the data.

## Discussion

Discussion If the data isn’t valid JSON, this method throws the DecodingError.dataCorrupted(_:) error. If a value within the JSON fails to decode, this method throws the corresponding error.
