jsonext 0.0.1 copy "jsonext: ^0.0.1" to clipboard
jsonext: ^0.0.1 copied to clipboard

Enhance Dart JSON manipulation with type safety, error-handling, and expressive extensions for seamless data handling.

Usage #

Explore the provided extension methods to streamline your JSON parsing. Here's a quick example:

import 'package:jsonext/jsonext.dart';

void main() {
  const data = {
    'name': 'John Doe',
    'age': 30,
    'isStudent': false,
    'birthDate': '1992-05-15',
    'height': 5.9,
    'grades': [90, 85, 78],
    'contact': {
      'email': '[email protected]',
      'phone': '123-456-7890',
    },
  };

  final name = data.asString('name', fallback: 'Unknown');
  print('Name: $name');

  final age = data.asIntN('age');
  print('Age: $age');

  final isStudent = data.asBool('isStudent', fallback: true);
  print('Is Student: $isStudent');

  final birthDate = data.asDateTime('birthDate', fallback: DateTime.now());
  print('Birth Date: $birthDate');

  final height = data.asDoubleN('height');
  print('Height: $height');

  final grades = data.asList('grades', fallback: []);
  print('Grades: $grades');

  final contact = data.asJson('contact', fallback: {});
  print('Contact: $contact');

  final hasEmail = contact.has('email');
  print('Has Email: $hasEmail');

  final email = contact.parseN(
    'email',
    (json) => json.asStringN('email'),
    fallback: null,
  );
  print('Email: $email');
}

Features #

  • Generic Type for JSON: Introduces the Json<T> type, allowing strong typing for JSON objects.

  • Callback Signature for JSON Parsing: Defines a callback signature, FromJsonCallback<T>, for creating custom parsers.

  • Extension Methods: Offers a set of concise extension methods for common data types like integers, strings, booleans, date-time, doubles, maps, lists, and custom JSON structures.

  • Parsing with Custom Callback: Versatile method, parseN, for parsing JSON values using a custom callback with optional fallback.

  • Check for Key Existence: The has method allows checking for the existence of a specific key in the JSON object.

6
likes
0
points
44
downloads

Publisher

unverified uploader

Weekly Downloads

Enhance Dart JSON manipulation with type safety, error-handling, and expressive extensions for seamless data handling.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on jsonext