有人知道在 Go 中 pretty-print JSON 输出的简单方法吗?
我想漂亮地打印 json.Marshal
的结果,以及格式化现有的 JSON 字符串,以便于阅读。
最佳答案
MarshalIndent
将允许您输出带有缩进和间距的 JSON。例如:
{
"data": 1234
}
indent
参数指定要缩进的字符序列。因此,json.MarshalIndent(data, "", "")
将使用四个空格进行缩进打印。
https://stackoverflow.com/questions/19038598/