Fancy diff output for JSON objects

blov · · 426 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Well, it came to me when I was writing 101st test for API. There are many asserters in golang world, but I needed readable output. Especially when it came to output a diff for 2 huge objects - expected and actual API responses. I got inspired by <a href="http://tlrobinson.net/projects/javascript-fun/jsondiff/" rel="nofollow">http://tlrobinson.net/projects/javascript-fun/jsondiff/</a> and implemented this one for Go: <a href="https://github.com/elgris/jsondiff" rel="nofollow">https://github.com/elgris/jsondiff</a></p> <p>Hope you will find it useful for your tests. Or point me to another useful tool that visualizes diffs in golang world :)</p> <hr/>**评论:**<br/><br/>memorylane: <pre><p>If you&#39;re already sorting the hash keys when Marshalling, then you can use <code>json.Indent()</code> on both items you want to diff, and then throw them at <a href="http://github.com/aryann/difflib" rel="nofollow">difflib</a>. Which is a general text diff package. It returns an array of diffs so you can work with the text as needed. It can also output HTML so you could use that to visualize the diff.</p> <p>I see that the library you wrote sorts the hash keys, so the above approach probably wasn&#39;t applicable to your situation.</p> <p><em>[Edit: fixed link]</em></p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

426 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传