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

MagicList
A List view over a List<dynamic> whose elements are wrapped on read.
MagicMap
A view over a Map<String, dynamic> with JavaScript-style member access.

Typedefs

JsonReplacer = Object? Function(String key, Object? value)
Signature of the replacer callback accepted by MagicMap.toJsonString and MagicList.toJsonString.

Exceptions / Errors

MagicMapException
Thrown by MagicMap and MagicList for invalid input or operations.