Skip to content

Instantly share code, notes, and snippets.

@alexd1971
Created November 18, 2019 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexd1971/e822d9d71d40596669c0c754dbf8081b to your computer and use it in GitHub Desktop.
Save alexd1971/e822d9d71d40596669c0c754dbf8081b to your computer and use it in GitHub Desktop.
import 'dart:convert';
void main() {
var org = <String, dynamic>{
'id': '12345678990',
'name': 'Roga & Kopyta',
'facebook': null
};
print(toCypherObject(org));
}
String toCypherObject(Map<String, dynamic> obj) {
final obj_ = Map.from(obj)..removeWhere((key, value) => value == null);
final encoded = obj_.entries.fold<List<String>>(
[],
(encodedEntries, entry) => encodedEntries
..add('${entry.key}: ${json.encode(entry.value)}')).join(', ');
return '{$encoded}';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment