jsonToCsvMulti1 static method

String jsonToCsvMulti1(
  1. String json
)

follows that json is in the format of "{...}"

Implementation

static String jsonToCsvMulti1(String json) {
  List<dynamic> map = jsonDecode(json);
  StringBuffer csvData = StringBuffer();
  List<String> heads = map[0].keys.toList();
  csvData.writeAll(heads, ",");
  csvData.write("\n");
  for (Map<String, dynamic> row in map) {
    for (String head in heads) {
      csvData.write("${row[head]},");
    }
    csvData.write("\n");
  }
  return csvData.toString();
}