json_events 1.2.2 json_events: ^1.2.2 copied to clipboard
A package for parsing large json files/objects. The package processes the json in a forward-only way and emits events based on the tokens it encounters.
example/json_events_example.dart
import "dart:async";
import "package:json_events/json_events.dart";
Future<void> main() async {
String jsonString = """
{
"compressionlevel": -1,
"height": 32,
"infinite": false,
"layers": [
{
"id": 16,
"image": "../images/background.jpg",
"name": "Image Layer 1",
"opacity": 1,
"type": "imagelayer",
"visible": true,
"x": 0,
"y": 0,
"a": {
"b": "1",
"c": "2"
}
}
],
"fields": [
"16",
"20",
"32"
],
"width": 32
}
""";
Stream<JsonEvent> s = Stream<String>.value(jsonString)
.transform(const JsonEventDecoder())
.flatten();
await for (JsonEvent je in s) {
// ignore: avoid_print
print("Event Type: ${je.type.name} Value: ${je.value}");
}
}