How to parse complex JSON in Flutter

Rei
6 min readOct 8, 2020

In the beginning, It’s a bit painful to parse JSON in Flutter. There are a couple of problems you will face while using data classes. That’s why I’ll explain to you problems and their solutions as simple as possible.

Motivation

Before we start handling JSON, we need to understand Data Class methods. That’s why I’ll show you what are the issues and their solutions, and how you get rid of all that kind of boilerplate code.

Also, there is an example project at the end of the article. You can check it out.

This article consists of two parts

  • Part 1: What are the problems and their basic solutions.
  • Part 2: How to take your code to the next level.

Part 1: Data Class Problems

  1. Instance of ‘Class’
  2. Equality
  3. Shallow Copying
  4. JSON To Dart
  5. The Null Guy

Let’s assume we have a simple User class with only one property.

--

--

Rei
Rei

Written by Rei

Victim of premature optimization, obsessed with improving programming skills. Also interested in UI/UX and photography. Personal Website: https://rei.codes

No responses yet