0%
JSON and Data Modeling — Chapter 17

Chapter 17 — JSON and Data Modeling

Part 1A — Learning Dart · Chapter 17 of 62 · 6 h

Chapter 17 — JSON and Data Modeling

Level: intermediate Estimated time: 6 h Prerequisites: Chapter 16 — Organizing a Dart Project (and Chapters 9, 12, 13, 14) What you'll be able to do by the end: turn JSON text into typed Dart objects and your Dart objects into JSON text, while cleanly handling missing values, inconsistent types, and format errors.


17.0 — Chapter Objectives

By the end of this chapter, you will be able to:

  • explain what JSON is for and why everyone uses it;
  • recognize the six JSON value types;
  • read and write a JSON object and a JSON array;
  • list the differences between JSON and a Dart Map;
  • follow JSON syntax rules (double quotes, no trailing comma);
  • decode text with jsonDecode() and encode with jsonEncode();
  • explain why jsonDecode() returns dynamic;
  • cast a result to Map<String, dynamic> and List<dynamic>;
  • write a model class with fromJson() and toJson();
  • do an object → JSON → object round trip with no loss;
  • handle nested objects and lists of nested objects;
  • write defensive code to deal with missing values and inconsistent types;
  • catch a FormatException on invalid JSON;
  • convert enums and DateTimes to JSON and back;
  • save and reload a game session in a JSON file;
  • understand what json_serializable is for;
  • connect all this to the REST APIs you will consume in Flutter.

Comments

Comments are powered by GitHub Discussions

Sign in with GitHub to join the discussion

Link copied!