Sitemap
Stanley Miller 

Stanley Miller 

iOS Developer. Author. Fan of the interesting. Written 100+ Swift/SwiftUI articles.

Member-only story

Advanced Swift: JSONDecoder

Learn about the JSONDecoder in Swift and SwiftUI

4 min readMay 14, 2025

--

Press enter or click to view image in full size

Imagine you’re building an app called MixtapeMagic, a slick little app that lets people recreate their favorite 2010s playlists. You need a way to fetch playlist data from a server: songs, durations, artists, and album art URLs. Of course, the server speaks JSON. But your app? It speaks Swift. So you need a translator.

That translator is called JSONDecoder.

Let’s set the scene:

This is what the server sends. Looks clean, but Swift has no idea what to do with it until you tell it how.

Now meet JSONDecoder, the polite Swift type that says, “I got this.” It takes raw JSON and transforms it into your Swift model.

Let’s create the matching Swift struct for our song.

The keyword Decodable means “I can be built from JSON.” It’s a protocol that says, “I know how to read from the server.”

--

--

Stanley Miller 
Stanley Miller 

Written by Stanley Miller 

iOS Developer. Author. Fan of the interesting. Written 100+ Swift/SwiftUI articles.