Json5 class

Represents a JSON5 object.

Mixed-in types

Constructors

Json5({bool caseSensitiveKeys = false, EDateTimeFormat? dateTimeFormat, bool readOnly = false, bool? sortedKeys})
Creates an empty Json5 object.
Json5.fromDiffs(Json5 json1, Json5 json2, {bool? caseSensitiveKeys, EDateTimeFormat? dateTimeFormat, bool readOnly = false, bool? sortedKeys})
Creates a new Json5 object containing entries from json2 that do not match the values from json1.
factory
Json5.fromFile(String path, {bool caseSensitiveKeys = false, EDateTimeFormat? dateTimeFormat, Map<String, dynamic>? params, bool readOnly = false, bool? sortedKeys})
Creates a Json5 object by reading and parsing the contents of the file at path.
factory
Json5.fromJson5(Json5 json5, {bool? caseSensitiveKeys, EDateTimeFormat? dateTimeFormat, bool readOnly = false, bool? sortedKeys})
Creates a Json5 object by performing a deep copy from another Json5 object.
factory
Json5.fromKeyAndValueLists({bool caseSensitiveKeys = false, EDateTimeFormat? dateTimeFormat, required List<String> keyList, bool readOnly = false, bool? sortedKeys, required List valueList})
Creates a Json5 object from a list of keys and a list of values. The values are lined up positionally with the keys.
factory
Json5.fromKeyToIndexMapAndValueList({bool caseSensitiveKeys = false, EDateTimeFormat? dateTimeFormat, required Map<String, int> keyToIndexMap, bool readOnly = false, bool? sortedKeys, required List valueList})
Creates a Json5 object from a map of keys to indexes and a list of values. The indexes represent the position of the values in the list.
factory
Json5.fromMap(Map jsonMap, {bool caseSensitiveKeys = false, EDateTimeFormat? dateTimeFormat, bool readOnly = false, bool? sortedKeys})
Creates a Json5 object from a Map.
factory
Json5.fromString(String jsonString, {bool? allowBlankString, bool caseSensitiveKeys = false, EDateTimeFormat? dateTimeFormat, Map<String, dynamic>? params, bool readOnly = false, bool? sortedKeys})
Decodes a JSON5 string into a Json5 object.
factory

Properties

caseSensitiveKeys bool
Indicates whether JSON keys are case sensitive.
final
dateTimeFormat EDateTimeFormat
The DateTime format used by this object.
final
entries Iterable<MapEntry<String, dynamic>>
Returns the key/value entries for this Json5 object.
no setter
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Returns true if this Json5 object is empty.
no setter
isNotEmpty bool
Returns true if this Json5 object is not empty.
no setter
keys Iterable<String>
Returns the keys for this Json5 object.
no setter
length int
Returns the number of key/value pairs in this Json5 object.
no setter
readOnly bool
Indicates whether this Json5 object is read-only.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sortedKeys bool
Indicates whether JSON keys are sorted case-insensitively.
final

Methods

addAll(Map? jsonMap) → void
Adds all entries from a Map to this Json5 object.
asBool(dynamic key, {bool defaultValue = false}) bool
Returns the boolean representation of the value associated with key.
inherited
asBoolList(dynamic key) List<bool>
Returns the list of bool values for key.
asBoolListOrNull(dynamic key) List<bool>?
Returns the list of bool values for key, or null if key is missing or null.
asBoolOrNull(dynamic key) bool?
Returns the boolean representation of the value associated with key, or null if key is missing or null.
inherited
asBoolSet(dynamic key) Set<bool>
Returns the set of bool values for key.
asBoolSetOrNull(dynamic key) Set<bool>?
Returns the set of bool values for key, or null if key is missing or null.
asDateTime(dynamic key, {DateTime? defaultValue}) DateTime
Returns the date/time representation of the value associated with key.
inherited
asDateTimeList(dynamic key) List<DateTime>
Returns the list of DateTime values for key.
asDateTimeListOrNull(dynamic key) List<DateTime>?
Returns the list of DateTime values for key, or null if key is missing or null.
asDateTimeOrNull(dynamic key) DateTime?
Returns the date/time representation of the value associated with key, or null if key is missing or null.
inherited
asDateTimeSet(dynamic key) Set<DateTime>
Returns the set of DateTime values for key.
asDateTimeSetOrNull(dynamic key) Set<DateTime>?
Returns the set of DateTime values for key, or null if key is missing or null.
asDateTimeUtc(dynamic key, [DateTime? defaultValue]) DateTime
Returns the UTC date/time representation of the value associated with key.
inherited
asDateTimeUtcOrNull(dynamic key) DateTime?
Returns the UTC date/time representation of the value associated with key, or null if key is missing or null.
inherited
asDouble(dynamic key, {double defaultValue = 0}) double
Returns the double representation of the value associated with key.
inherited
asDoubleList(dynamic key) List<double>
Returns the list of double values for key.
asDoubleListOrNull(dynamic key) List<double>?
Returns the list of double values for key, or null if key is missing or null.
asDoubleOrNull(dynamic key) double?
Returns the double representation of the value associated with key, or null if key is missing or null.
inherited
asDoubleSet(dynamic key) Set<double>
Returns the set of double values for key.
asDoubleSetOrNull(dynamic key) Set<double>?
Returns the set of double values for key, or null if key is missing or null.
asDynamicList(dynamic key) List
Returns the list of values for key.
asDynamicListOrNull(dynamic key) List?
Returns the list of values for key, or null if key is missing or null.
asDynamicSet(dynamic key) Set
Returns the set of values for key.
asDynamicSetOrNull(dynamic key) Set?
Returns the set of values for key, or null if key is missing or null.
asInt(dynamic key, {int defaultValue = 0}) int
Returns the integer representation of the value associated with key.
inherited
asIntList(dynamic key) List<int>
Returns the list of int values for key.
asIntListOrNull(dynamic key) List<int>?
Returns the list of int values for key, or null if key is missing or null.
asIntOrNull(dynamic key) int?
Returns the integer representation of the value associated with key, or null if key is missing or null.
inherited
asIntSet(dynamic key) Set<int>
Returns the set of int values for key.
asIntSetOrNull(dynamic key) Set<int>?
Returns the set of int values for key, or null if key is missing or null.
asJson(dynamic key) Json5
Returns the Json5 object for key.
asJsonList(dynamic key) List<Json5>
Returns the list of Json5 values for key.
asJsonListOrNull(dynamic key) List<Json5>?
Returns the list of Json5 values for key, or null if key is missing or null.
asJsonOrNull(dynamic key) Json5?
Returns the Json5 object for key, or null if key is missing or null.
asJsonSet(dynamic key) Set<Json5>
Returns the set of Json5 values for key.
asJsonSetOrNull(dynamic key) Set<Json5>?
Returns the set of Json5 values for key, or null if key is missing or null.
asString(dynamic key, {String defaultValue = ""}) String
Returrns the string representation of the value associated with key.
inherited
asStringList(dynamic key) List<String>
Returns the list of String values for key.
asStringListOrNull(dynamic key) List<String>?
Returns the list of String values for key, or null if key is missing or null.
asStringOrNull(dynamic key) String?
Returns the string representation of the value associated with key, or null if key is missing or null.
inherited
asStringSet(dynamic key) Set<String>
Returns the set of String values for key.
asStringSetOrNull(dynamic key) Set<String>?
Returns the set of String values for key, or null if key is missing or null.
clear() → void
Clears all entries from this Json5 object.
containsKey(dynamic key) bool
Indicates whether the key exists in the collection.
inherited
isNotNull(dynamic key) bool
Returns true if the value associated with key is not null.
inherited
isNull(dynamic key) bool
Returns true if the value associated with key is null.
inherited
joinStrings(List keyList, {bool includeBlankValues = false, String separator = ","}) String
Returns a string containing the string values for all keys.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove(dynamic key) → dynamic
Removes the entry for key and returns its value.
removeBool(dynamic key, {bool defaultValue = false}) bool
Removes the entry for key and returns its boolean representation.
removeBoolList(dynamic key) List<bool>
Removes the list entry for key and returns a detached list of bool elements.
removeBoolListOrNull(dynamic key) List<bool>?
Removes the list entry for key and returns a detached list of bool elements, or null if key is missing or null.
removeBoolOrNull(dynamic key) bool?
Removes the entry for key and returns its boolean representation, or null if key is missing or null.
removeBoolSet(dynamic key) Set<bool>
Removes the set entry for key and returns a detached set of bool elements.
removeBoolSetOrNull(dynamic key) Set<bool>?
Removes the set entry for key and returns a detached set of bool elements, or null if key is missing or null.
removeDateTime(dynamic key, {DateTime? defaultValue}) DateTime
Removes the entry for key and returns its date/time representation.
removeDateTimeList(dynamic key) List<DateTime>
Removes the list entry for key and returns a detached list of DateTime elements.
removeDateTimeListOrNull(dynamic key) List<DateTime>?
Removes the list entry for key and returns a detached list of DateTime elements, or null if key is missing or null.
removeDateTimeOrNull(dynamic key) DateTime?
Removes the entry for key and returns its date/time representation, or null if key is missing or null.
removeDateTimeSet(dynamic key) Set<DateTime>
Removes the set entry for key and returns a detached set of DateTime elements.
removeDateTimeSetOrNull(dynamic key) Set<DateTime>?
Removes the set entry for key and returns a detached set of DateTime elements, or null if key is missing or null.
removeDateTimeUtc(dynamic key, [DateTime? defaultValue]) DateTime
Removes the entry for key and returns its UTC date/time representation.
removeDateTimeUtcOrNull(dynamic key) DateTime?
Removes the entry for key and returns its UTC date/time representation, or null if key is missing or null.
removeDouble(dynamic key, {double defaultValue = 0}) double
Removes the entry for key and returns its double representation.
removeDoubleList(dynamic key) List<double>
Removes the list entry for key and returns a detached list of double elements.
removeDoubleListOrNull(dynamic key) List<double>?
Removes the list entry for key and returns a detached list of double elements, or null if key is missing or null.
removeDoubleOrNull(dynamic key) double?
Removes the entry for key and returns its double representation, or null if key is missing or null.
removeDoubleSet(dynamic key) Set<double>
Removes the set entry for key and returns a detached set of double elements.
removeDoubleSetOrNull(dynamic key) Set<double>?
Removes the set entry for key and returns a detached set of double elements, or null if key is missing or null.
removeDynamicList(dynamic key) List
Removes the list entry for key and returns a detached list of values.
removeDynamicListOrNull(dynamic key) List?
Removes the list entry for key and returns a detached list of values, or null if key is missing or null.
removeDynamicSet(dynamic key) Set
Removes the set entry for key and returns a detached set of values.
removeDynamicSetOrNull(dynamic key) Set?
Removes the set entry for key and returns a detached set of values, or null if key is missing or null.
removeInt(dynamic key, {int defaultValue = 0}) int
Removes the entry for key and returns its integer representation.
removeIntList(dynamic key) List<int>
Removes the list entry for key and returns a detached list of int elements.
removeIntListOrNull(dynamic key) List<int>?
Removes the list entry for key and returns a detached list of int elements, or null if key is missing or null.
removeIntOrNull(dynamic key) int?
Removes the entry for key and returns its integer representation, or null if key is missing or null.
removeIntSet(dynamic key) Set<int>
Removes the set entry for key and returns a detached set of int elements.
removeIntSetOrNull(dynamic key) Set<int>?
Removes the set entry for key and returns a detached set of int elements, or null if key is missing or null.
removeJsonList(dynamic key) List<Json5>
Removes the list entry for key and returns a detached list of Json5 elements.
removeJsonListOrNull(dynamic key) List<Json5>?
Removes the list entry for key and returns a detached list of Json5 elements, or null if key is missing or null.
removeJsonOrNull(dynamic key) Json5?
Removes the Json5 object for key, or null if key is missing or null.
removeJsonSet(dynamic key) Set<Json5>
Removes the set entry for key and returns a detached set of Json5 elements.
removeJsonSetOrNull(dynamic key) Set<Json5>?
Removes the set entry for key and returns a detached set of Json5 elements, or null if key is missing or null.
removeString(dynamic key, {String defaultValue = ""}) String
Removes the entry for key and returns its string representation.
removeStringList(dynamic key) List<String>
Removes the list entry for key and returns a detached list of String elements.
removeStringListOrNull(dynamic key) List<String>?
Removes the list entry for key and returns a detached list of String elements, or null if key is missing or null.
removeStringOrNull(dynamic key) String?
Removes the entry for key and returns its string representation, or null if key is missing or null.
removeStringSet(dynamic key) Set<String>
Removes the set entry for key and returns a detached set of String elements.
removeStringSetOrNull(dynamic key) Set<String>?
Removes the set entry for key and returns a detached set of String elements, or null if key is missing or null.
set(dynamic key, dynamic value) → void
Sets the value for key to value.
setFromJson(Json5 copyFromJson) → void
Copies entries from copyFromJson into this object. Performs a deep copy of nested Json5 objects and Lists.
setFromKeyAndValueLists(List<String>? keyList, List? valueList) → void
Updates this Json5 object with the entries from keyList and valueList.
setFromKeyToIndexAndValueList(Map<String, int>? keyToIndexMap, List? valueList) → void
Updates this Json5 object with the entries from keyToIndexMap and valueList.
setFromMap(Map copyFromMap) → void
Updates this Json5 object with the entries from copyFromMap.
setIfChanged(dynamic key, Json5 oldJson, dynamic newValue) → void
Sets the value for key if the newValue has changed for the oldJson value.
setIfNewValueIsNotEmpty(dynamic key, dynamic newValue) → void
Sets the value for key only if newValue is not null and not empty (for Strings, Iterables, Maps, and Json5 objects).
setIfNewValueIsNotNull(dynamic key, dynamic newValue) → void
Sets the value for key only if newValue is not null.
setIfNotEqual(dynamic key, {required dynamic newValue, required dynamic oldValue}) → void
Sets the value for key only if newValue is not equal to oldValue. For Iterables, equality is determined by having the same elements in the same order. For Maps, equality is determined by having the same keys with equal values. For Json5 objects, equality is determined by having the same keys with equal values. For other types, equality is determined by the == operator.
toFile(String path, {bool includeComments = true, bool json5 = true}) → void
Writes the formatted JSON5 representation of this object to the file at path.
toFormattedString({bool includeComments = true, bool json5 = true}) String
Returns a pretty-printed JSON or JSON5 string with 2-space indentation.
toJsonString({bool? json5}) String
Generates a JSON5 or JSON string representation of the object. For a pretty-printed version, use toFormattedString. Pass json5 to override the format (true for JSON5, false for standard JSON); defaults to defaultUseJson5ForToString.
toMap() Map<String, dynamic>
Converts this Json5 object to a standard Map.
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator [](dynamic key) → dynamic
Returns the value associated with key.
inherited
operator []=(dynamic key, dynamic value) → void
Delegates the assignment to the set method, for example, json5"key1" = 1 is equivalent to json5.set("key1", 1).

Static Properties

defaultAllowBlankString bool
Default setting for whether Json5.fromString allows a blank string input (false by default).
getter/setter pair
defaultDateTimeFormat EDateTimeFormat
Default DateTime format used for DateTime accessors and serialization.
getter/setter pair
defaultUseJson5ForToString bool
Default format used by toJsonString and toString (true for JSON5, false for standard JSON).
getter/setter pair
defaultUseSortedKeys bool
Default setting for whether newly constructed Json5 objects sort their keys case-insensitively.
getter/setter pair
emptyBoolList List<bool>
An empty unmodifiable bool list.
final
emptyBoolSet Set<bool>
An empty unmodifiable bool set.
final
emptyDateTimeList List<DateTime>
An empty unmodifiable DateTime list.
final
emptyDateTimeSet Set<DateTime>
An empty unmodifiable DateTime set.
final
emptyDoubleList List<double>
An empty unmodifiable double list.
final
emptyDoubleSet Set<double>
An empty unmodifiable double set.
final
emptyDynamicList List
An empty unmodifiable dynamic list.
final
emptyDynamicSet Set
An empty unmodifiable dynamic set.
final
emptyIntList List<int>
An empty unmodifiable int list.
final
emptyIntSet Set<int>
An empty unmodifiable int set.
final
emptyJson Json5
An empty unmodifiable Json5 object.
final
emptyJsonList List<Json5>
An empty unmodifiable Json5 list.
final
emptyJsonSet Set<Json5>
An empty unmodifiable Json5 set.
final
emptyStringList List<String>
An empty unmodifiable String list.
final
emptyStringSet Set<String>
An empty unmodifiable String set.
final

Static Methods

decodeMultiple({bool caseSensitiveKeys = false, EDateTimeFormat? dateTimeFormat, required String jsonString, Map<String, dynamic>? params, bool readOnly = false, bool? sortedKeys}) → ({List<Json5> jsonList, String unprocessed})
Parses a string containing multiple JSON5 objects and returns them as a list, along with any trailing unprocessed text.
escapeString(String originalValue) String
Escapes special characters (control characters, quotes, backslashes) in originalValue for JSON/JSON5 string output.
parseAny(String jsonString, {bool caseSensitiveKeys = false, EDateTimeFormat? dateTimeFormat, Map<String, dynamic>? params, bool readOnly = false, bool? sortedKeys}) → dynamic
Decodes any JSON5 string into its dynamic Dart representation (which could be a Json5 object, List, String, num, bool, or null).