Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Dart

Idiom #333 Pretty-print object in JSON

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

import 'dart:convert';
var encoded = const JsonEncoder.withIndent('  ').convert(x);
print(encoded);
import "encoding/json"
import "fmt"
buffer, err := json.MarshalIndent(x, "", "  ")
if err != nil {
	log.Fatal(err)
}
fmt.Println(string(buffer))

Using 2 spaces as indentation

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