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