How to resolve deep json object in Dart
If we are not on the edge with GRPC and Protocol Buffer, then most likely we are going to deal with Restful and JSON. In one of my Flutter apps I needed to consume JSON
The guide at https://flutter.dev/docs/development/data-and-backend/json is definitely the way to go.
Currently there are 2 ways. One is to manually use
Map<String, dynamic> user = jsonDecode(jsonString);
The other way is to use json_serializable to generate parsing code
The problem with manual approach is that it involves lot of boilerplate code, especially when accessing property inside deeply nested json. The problem with code generation approach is that it does not always fit our need and may lack of customization.
Therefore I created json_resolve which allows us to access json using keypath, with type checking and safety in mind. The code is small, simple to reason and tested.
final String byProperty = resolve(json: json, path: "movie", defaultValue: "error");