How to convert a JSON object into data in Swift

Oscar de la Hera Gomez
Two flowers that represent Swift and Xcode with the text "Encode JSON" beneath them.

Using do-try-catch syntax, pass in the JSON type and data to a JSONDecoder to encode JSON into data.

To encode a JSON object into data use the functionality outlined below. It is available in our Open Source starter project.

To use the function, use a line of code similar to the one below.

Please note YourDataType is the JSON struct and bytes are the data.

let JSON: Data? = convertDataToJSON(item: JSONItem)

Looking to convert data into a JSON object ?

Consult the tutorial linked below to learn how to convert data into a JSON object in Swift.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details