prettyJson function

String prettyJson(
  1. String source
)

Indents valid JSON; anything else is shown as it came.

Implementation

String prettyJson(String source) {
  try {
    return const JsonEncoder.withIndent('  ').convert(jsonDecode(source));
  } on FormatException {
    return source;
  }
}