Logo

Programming-Idioms

  • Ruby

Idiom #333 Pretty-print object in JSON

Print the object x in human-friendly JSON format, with newlines and indentation.

require 'json'
puts JSON.pretty_generate(x)
import 'dart:convert';
var encoded = const JsonEncoder.withIndent('  ').convert(x);
print(encoded);

New implementation...
< >
programming-idioms.org