Repository navigation
v1.3.0
-
New
mapValueforasMap*()andasJsonObject*()parses the values of a map, like the mapper ofasList*does for the items of a list #73.
An error inside a value reports the full location, likeadidas.id.// {"nike": {"id": "421"}, "adidas": {"id": "532"}} Map<String, Shoe> shoes = pick(json).asJsonObjectOrEmpty(mapValue: Shoe.fromPick);
-
New
whenNullValuemaps the entries with anullvalue, whichmapValueignores, likewhenNulldoes for lists.Map<String, Shoe?> shoes = pick(json).asJsonObjectOrEmpty( mapValue: Shoe.fromPick, whenNullValue: (pick) => null, );
-
New
mapKeyconverts the keys.
It receives a pick of the key, so the usual parsers work on it.// {"421": {"name": "Nike Zoom Fly 3"}} Map<int, Shoe> shoes = pick(json).asMapOrEmpty( mapKey: (key) => key.asIntOrThrow(), mapValue: Shoe.fromPick, );
The keys of
asJsonObject*()stayStrings, itsmapKeycan rename them.
UseasMap*()to convert the keys to another type. -
All six parsers are affected:
asMapOrThrow(),asMapOrEmpty(),asMapOrNull(),asJsonObjectOrThrow(),asJsonObjectOrEmpty()andasJsonObjectOrNull().
asJsonObject*()got two type parameters for it, a call without arguments still returns aMap<String, Object?>. -
New
asPlainListOrThrow(),asPlainListOrEmpty()andasPlainListOrNull()return the items of aListas they are, without a mapper #74.
Declare the item type to get a typed list, an item of another type throws aPickExceptionthat names it.List<Object?> items = pick(json, 'tags').asPlainListOrEmpty(); List<String> tags = pick(json, 'tags').asPlainListOrEmpty();