JsonObject extension type
A zero-cost wrapper around a JSON object.
This type exists to provide a subtype of JsonValue that is an object.
Similar to JsonAny, this type provides helper methods to read fields.
Example
import 'package:jsonut/jsonut.dart';
void main() {
const json = '{"name": "John Doe", "age": 42}';
final object = JsonObject.parse(json);
print(object['name'].string()); // John Doe
print(object['age].number()); // 42
print(object['email'].stringOrNull()); // null
}
Constructors
-
JsonObject(Map<
String, JsonValue> value) -
Returns and treats the given
value
as a JSON object.factory - JsonObject.parse(String input)
-
Parses and casts the given
input
as an object.factory -
JsonObject.parseUtf8(List<
int> bytes) -
Parses and returns the given UTF8-encoded
bytes
as an object.factory
Properties
-
entries
→ Iterable<
MapEntry< String, JsonAny> > -
The map entries of this.
no setterinherited
-
fields
→ Map<
String, JsonAny> -
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isEmpty → bool
-
Whether there is no key/value pair in the map.
no setterinherited
- isNotEmpty → bool
-
Whether there is at least one key/value pair in the map.
no setterinherited
-
keys
→ Iterable<
String> -
The keys of this.
no setterinherited
- length → int
-
The number of key/value pairs in the map.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
values
→ Iterable<
JsonAny> -
The values of this.
no setterinherited
Methods
-
addAll(
Map< String, JsonAny> other) → void -
Adds all key/value pairs of
other
to this map.inherited -
addEntries(
Iterable< MapEntry< newEntries) → voidString, JsonAny> > -
Adds all key/value pairs of
newEntries
to this map.inherited -
asAny(
) → JsonAny -
Converts this object into a JsonAny.
inherited
-
cast<
V extends JsonValue> () → Map< JsonString, V> -
Returns the object casting all values to the given type
V
.override -
clear(
) → void -
Removes all entries from the map.
inherited
-
containsKey(
Object? key) → bool -
Whether this map contains the given
key
.inherited -
containsValue(
Object? value) → bool -
Whether this map contains the given
value
.inherited -
convert<
T> (T convert(JsonObject)) → T - Returns the result of applying the given convert to this JSON object.
-
deepGet(
Iterable< String> keys) → JsonAny -
Given a path of
keys
, returns the value at that path. -
deepGetOrNull(
Iterable< String> keys) → JsonAny -
Given a path of
keys
, returns the value at that path, ornull
. -
forEach(
void action(String key, JsonAny value)) → void -
Applies
action
to each key/value pair of the map.inherited -
map<
K2, V2> (MapEntry< K2, V2> convert(String key, JsonAny value)) → Map<K2, V2> -
Returns a new map where all entries of this map are transformed by
the given
convert
function.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
putIfAbsent(
String key, JsonAny ifAbsent()) → JsonAny -
Look up the value of
key
, or add a new entry if it isn't there.inherited -
remove(
Object? key) → JsonAny? -
Removes
key
and its associated value, if present, from the map.inherited -
removeWhere(
bool test(String key, JsonAny value)) → void -
Removes all entries of this map that satisfy the given
test
.inherited -
toString(
) → String -
A string representation of this object.
inherited
-
update(
String key, JsonAny update(JsonAny value), {JsonAny ifAbsent()?}) → JsonAny -
Updates the value for the provided
key
.inherited -
updateAll(
JsonAny update(String key, JsonAny value)) → void -
Updates all values.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
String name) → JsonAny -
Returns a zero-cost wrapper for the field with the given
name
.override -
operator []=(
String name, JsonValue value) → void -
Sets the field with the given
name
to the givenvalue
.override