checked_json 0.2.1
checked_json: ^0.2.1 copied to clipboard
A JSON object type you only get by checking a value, with typed readers that name the field that is absent or the wrong shape.
Changelog #
0.2.1 #
- Add
deepFrozen(): a copy all the way down that refuses changes. Every nested object and list is copied and made unmodifiable, field and list order are kept (sojsonEncodewrites the same bytes), and a nested map comes back as aMap<String, Object?>. A valuejsonEncodecannot write as it is (a key that is not a string, aSet, aDateTime,NaN) is aJsonFieldExceptionwhosefieldis its path, such asa.b[2]. A key is never turned into a string. frozen()andJsonObject.unmodifiableare unchanged and stay shallow.
0.2.0 #
-
Breaking:
JsonObjectno longer implementsMap<String, Object?>, soobj['k']andobj['k'] = vdo not compile. To migrate:0.1.x 0.2.0 obj['k']a typed reader ( obj.string('k'), ...), orobj.raw('k')for a value read with a pattern or passed onJsonObject.of({...obj, 'k': v})obj.withFields({'k': v})JsonObject.of({...a, ...b})JsonObject.merge([a, b])JsonObject.of({...obj}..remove('k'))obj.without({'k'})obj.keys,obj.entriesobj.keys, with a reader for each valueobj.containsKey(k)obj.has(k)JsonObject.unmodifiable(obj)obj.frozen()objpassed to a parameter declared as aMapobj.asUncheckedMap()jsonEncode(obj)unchanged: it writes a JsonObjectas it is -
Add
withFields,JsonObject.mergeandwithout, which each make a new object from others, andkeys. -
Add
frozen(), a copy that refuses changes. Shallow: nested objects and lists are shared. -
Add
asUncheckedMap(), a read-only map view for a parameter declared as aMap. -
JsonObjectimplementsObject, so it is never null and an extension onT extends Objectapplies to it. (Withoutimplements Map, it would otherwise be only anObject?.)
0.1.0 #
- Add
JsonObject, an extension type overMap<String, Object?>that can only be made from raw data through a door that checks it (JsonObject.decode,JsonObject.parse), with typed readers (string,integer,number,boolean,object,list,strings,objects, each with anOrNulltwin) plushasandraw. - Add
JsonFieldException, theFormatExceptiona reader throws naming the field that is absent or the wrong shape, and the shape it wanted. - Add
wholeNumber, which reads3or3.0as anintand refuses fractions and doubles of 2^53 or more in size. - Licensed Apache-2.0.