Converting Dart models into JSON
JSON has become the standard format for storing, transporting, and sharing data between applications: several web services and databases use JSON to receive and serve data. Later in this chapter, we will learn how to store data in a device, but in this recipe, we will learn how to serialize (or encode) and deserialize (or decode) data structures from/to JSON.
- JSON stands for JavaScript Object Notation. Even if it largely follows JavaScript syntax, it can be used independently from Javascript. Most modern languages, including Dart, have methods to read and write JSON data.
The following screenshot shows an example of a JSON data structure:
- As you can see, JSON is a text-based format that describes data in key-value pairs: each object (a pizza, in this example) is included curly brackets. In the object, you can specify several properties or fields. The key is generally included in quotes; then, you put a colon, and then the value. All key-value pairs...