jsonValueToStorage function

Object? jsonValueToStorage(
  1. Object? v
)

Reverse of storageToJsonValue: decode a value coming out of jsonDecode back to its in-memory storage form. Tagged BLOB sentinels become Uint8List.

Implementation

Object? jsonValueToStorage(Object? v) {
  if (v == null) return null;
  if (v is bool || v is num || v is String) return v;
  if (v is List) return v.map(jsonValueToStorage).toList();
  if (v is Map) {
    final m = v.cast<String, Object?>();
    if (m.length == 1 && m.containsKey(kBlobJsonTag)) {
      final hex = m[kBlobJsonTag];
      if (hex is String) return _hexToBytes(hex);
    }
    return m.map((k, val) => MapEntry(k, jsonValueToStorage(val)));
  }
  return v;
}