Member-only story
Swift JSON Parsing
Combine the most popular data format with Swift

JSON stands for JavaScript Object Notation. It’s a popular text-based data format used everywhere for representing structured data. Almost every programming language supports it with Swift being no exception. You are going to use JSON a lot throughout your career, so make sure you don’t miss out.
In Swift, parsing JSON is a common necessity. Luckily, working with JSON is easy in Swift. It doesn’t even require setting up any external dependencies.

Let’s get started.
JSON Decoding in Swift
For instance, let’s say you perform a network request to retrieve some videos from a website. As a response, you get a JSON object:
In your app, you want to convert this JSON to a Swift object. To do this, let’s store this JSON data in a structure.
To start off, let’s create a structure that conforms to the Decodable
protocol to store all the listed properties found in the JSON data:
You can now parse the JSON data by using the above structure in conjunction with the built-in JSONDecoder()
:
That’s all there is to it. Congratulations — now you know the basics of JSON parsing in Swift.