jsonEncode from dart:convert walks a Dart Map/List/scalar and returns the equivalent JSON text. Maps preserve their insertion order and inner List values are encoded element by element.

Program

Play the program to build a small user map and encode it.

json_encode.dart
import 'dart:convert';

void main() {
  var user = {'name': 'Ada', 'scores': [9, 12, 6]};
  var encoded = jsonEncode(user);
  print('json = $encoded');
}
dart:convert `import 'dart:convert'` brings in `jsonEncode` and `jsonDecode`.
jsonEncode `jsonEncode(value)` returns a JSON-text `String` representing the map, list, or scalar.
nested list The `scores` list is encoded element by element inside the surrounding object.