Parsing JSON Just Became Super Easy in Swift 4 with Decodable

Transforming JSON into model objects in your apps just became a whole lot easier with the introduction of Decodable in Swift 4. In today’s lesson, I want to walk through the old way of using JSONSerialization and then show you the new JSONDecoder method. We can retire a bunch of JSON serializer pods now that we have this feature natively supported.

URLs for JSON blobs:

Completed Source Code

Instagram Firebase Course

Facebook Group

iOS Basic Training Course

Follow me on Twitter:

26 thoughts on “Parsing JSON Just Became Super Easy in Swift 4 with Decodable”

  1. In the video you go print(, websiteDescription.description)

    But if you also wanted to print the first course how would you go about doing that?

  2. Hi Brian. Great tutorial. Thank you. Can you show us how to view the data in a table View Cell? Thanks!

  3. your videos are so awesome. Please make a video on how to upload multiple images to REST server. Searched a lot in youtube and also in stack overflow but couldn't find any proper solution. Thanks

  4. struct jsonstruct:Decodable {
    let name:String
    let capital:String
    let alpha2Code:String
    let alpha3Code:String
    let region:String
    let subregion:String

    class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet var tableview: UITableView!

    var arrdata = [jsonstruct]()
    override func viewDidLoad() {

    func getdata(){
    let url = URL(string: "")
    URLSession.shared.dataTask(with: url!) { (data, response, error) in
    do{if error == nil{
    self.arrdata = try JSONDecoder().decode([jsonstruct].self, from: data!)

    for mainarr in self.arrdata{
    DispatchQueue.main.async {


    print("Error in get json data")



    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return self.arrdata.count

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell:TableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell") as! TableViewCell
    cell.lblname.text = "Name : (arrdata[indexPath.row].name)"
    cell.lblcapital.text = "Capital : (arrdata[indexPath.row].capital)"
    return cell

  5. Timestamp to the 1 line of code he mentioned in the title? I'm watching the video and I'm looking at about 70 lines of code so far.

  6. I want to take backup of contact list in my app, If you could help me please give me an idea. I have already accessed my contacts list in app and taken the data in a dictionary; further where to send this data and save it, I have no idea.Would it be useful if I send it to gmail in the form of json and then access accordingly??

  7. It has become hard for me to pass by any of your videos without giving it a *LIKE*.
    Some awesome content here.

  8. how can you think all json objects include same length parameters ? my json tree is complicated. some categories has 10 keys, some has 20 keys with 10 value. this is bullshit. Click bait

  9. Do I need to add all properties in the Decodable Struct? Can I just add only the properties that I want to use/parse?


Leave a Comment