Immutable JSON wrapper for Dart with Qt-style API. Inspired by QJsonObject
and QJsonArray
from Qt. Designed to work with Variant
types from dart_qvariant.
- Immutable
JsonObject
andJsonList
wrappers - Safe access to values using
Variant
- Strong separation of primitives, lists, and objects
- Supports parsing from JSON string
- Converts back to Dart map/list or JSON string
dart pub add dart_qjson
import 'package:dart_qjson/dart_qjson.dart';
void main() {
final jsonString = '''
{
"user": {
"id": 1,
"name": "Alice",
"isActive": true
},
"tags": ["dart", "flutter"],
"score": 42.5,
"metadata": null
}
''';
final jsonObject = JsonObject.fromJsonString(jsonString);
final user = jsonObject.getObject("user");
print("User ID: ${user?.get("id")?.toInt()}");
print("User Name: ${user?.get("name")?.toText()}");
final tags = jsonObject.getList("tags");
for (var i = 0; i < (tags?.length ?? 0); i++) {
print("Tag $i: ${tags?.get(i)?.toText()}");
}
final score = jsonObject.get("score");
print("Score: ${score?.toDouble()}");
final metadata = jsonObject.get("metadata");
print("Metadata is null: ${metadata == null}");
print("Back to JSON: ${jsonObject.toJsonString}");
}