safe_json 1.0.4 safe_json: ^1.0.4 copied to clipboard
A happy way to parse JSON in Dart which can avoid crush and show error detail in console. Primary purpose of this library is to find out backend error(incomplete data) at the first time.
safe_json #
Small, easy to use null safety json decoding library. The primary goal of this library is to find out bugs in the early stages of development when parsing JSON values.
Features #
- Safely parse JSON values to various data types.
- Provide default values when parsing fails.
- Error logging with file location.
Examples #
final name = json.safeString('name', defaultValue: 'John');
final age = json.safeInt('age');
final articles = json.safeList<String>('articles');
final vehicles = json.safeList<Vehicle>('vehicles', itemParse: (json) => Vehicle.fromJson(json));
//set to true if want to disable error logging (usually in production)
SafeJsonLibrary.skipLog = true;
Console Logs #
Installation #
Add safe_json
to your pubspec.yaml
file:
dependencies:
safe_json: ^1.0.1