maybeAddQuotes function encoder
dynamic
maybeAddQuotes(
- dynamic value
Return a quoted String value for JSON if the current value is a String.
Example:
Given a String value foo will return:
"foo"
Given an int value 10 will return:
10
Implementation
dynamic maybeAddQuotes(dynamic value) {
if (value is List) {
return value.map<dynamic>(maybeAddQuotes).toList();
}
if (value is Map) {
return value.map<dynamic, dynamic>((dynamic k, dynamic v) {
return MapEntry<dynamic, dynamic>(maybeAddQuotes(k), maybeAddQuotes(v));
});
}
if (value is String) {
return '"$value"';
}
if (value is JsonNode) {
return maybeAddQuotes(value.data);
}
return value;
}