magic_map library
Path-based and typed access to deeply nested maps and lists.
The two public types are MagicMap (wraps a Map<String, dynamic>) and
MagicList (wraps a List<dynamic>). Both are views over plain Dart
collections: reading a nested map or list returns another view over the
same underlying data, and every write goes straight through to it.
final data = MagicMap({'user': {'name': 'Alice', 'tags': ['a', 'b']}});
final name = data.requireAs<String>('user.name'); // Alice
final tags = data.getListOf<String>('user.tags') ?? []; // List<String>
data.set('user.tags[1]', 'z'); // writes through
print(data.getPath('user.tags.1')); // z
Casting a MagicMap to dynamic additionally enables JavaScript-style
dot access (d.user.name).
Classes
Typedefs
- JsonReplacer = Object? Function(String key, Object? value)
-
Signature of the
replacercallback accepted byMagicMap.toJsonStringandMagicList.toJsonString.
Exceptions / Errors
- MagicMapException
- Thrown by MagicMap and MagicList for invalid input or operations.