jsonut 0.4.1+3 copy "jsonut: ^0.4.1+3" to clipboard
jsonut: ^0.4.1+3 copied to clipboard

A minimal utility kit for working with JSON in a typesafe manner.

jsonut #

A minimal utility kit for working with JSON in a typesafe manner.

βœ… Health πŸš€ Release πŸ“ Docs ♻️ Maintenance
Build status for package/jsonut Pub version for package/jsonut Dart documentation for package/jsonut GitHub Issues for package/jsonut

By default, Dart offers very little in the way of JSON parsing and serialization. While upcoming features like macros1 are promising, they are not yet available (as of 2024-03-1). This package uses a (at the time of writing) new language feature, extension types to provide lightweight, type-safe JSON parsing:

import 'package:jsonut/jsonut.dart';

void main() {
  final string = '{"name": "John Doe", "age": 42}';
  final person = JsonObject.parse(string);
  print(person['name'].string()); // John Doe
  print(person['age'].number()); // 42
}

Features #

  • 🦺 Typesafe: JSON parsing and serialization is type-safe and easy to use.
  • πŸ’¨ Lightweight: No dependencies, code generation, or reflection.
  • πŸ’ͺ🏽 Flexible: Parse lazily or validate eagerly, as needed.
  • 🚫 No Bullshit: Use as little or as much as you need.

Getting Started #

Simply add the package to your pubspec.yaml:

dependencies:
  jsonut: ^0.4.0

Or use the command line:

dart pub add jsonut
flutter packages add jsonut

Or, even just copy paste the code (a single .dart file) into your project:

curl -o lib/jsonut.dart https://raw.githubusercontent.com/matanlurey/jsonut/main/lib/jsonut.dart

Benchmarks #

A basic decoding benchmark is included in the benchmark/ directory. To run it:

# JIT
dart run benchmark/decode.dart

# AOT
dart compile exe benchmark/decode.dart
./benchmark/decode.exe

On my machineβ„’, a M2 MacBook Pro, there is roughly a <10% overhead compared to just using the object['...'] as ... pattern, or dynamic calls in JIT mode. In AOT mode, jsonut is faster than dynamic calls, and ~3% slower at decoding.

In short, the overhead is minimal compared to the benefits.

Contributing #

We welcome contributions to this package!

Please file an issue before contributing larger changes.

This package uses repository specific tooling to enforce formatting, static analysis, and testing. Please run the following commands locally before submitting a pull request:

  • ./dev.sh --packages packages/jsonut check
  • ./dev.sh --packages packages/jsonut test
11
likes
160
points
15
downloads

Publisher

verified publisherlurey.dev

Weekly Downloads

A minimal utility kit for working with JSON in a typesafe manner.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on jsonut