<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 8.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/JSONDecoder/decode(_:from:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation11JSONDecoderC6decode_4fromxxm_AA4DataVtKSeRzlF"
  },
  "title" : "decode(_:from:)"
}
-->

# decode(_:from:)

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

```
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

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

## Discussion

If the data isn’t valid JSON, this method throws the <doc://com.apple.documentation/documentation/Swift/DecodingError/dataCorrupted(_:)> error. If a value within the JSON fails to decode, this method throws the corresponding error.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)