我怎样才能让jq按字母顺序漂亮地打印json排序键 [英] How can I get jq to pretty print json ordering keys alphabetically
本文介绍了我怎样才能让jq按字母顺序漂亮地打印json排序键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用jq漂亮地打印了非常复杂的json.然后使用diff比较不同版本.有没有办法让jq通过按键按字母顺序对输出进行排序?
I use jq to pretty print very complicated json. then use diff to compare different version. Is there a way I can get jq to order the output alphabetically by keys?
更快的xml对象映射器对此具有支持
faster xml object mappers have support for this
prettyPrintObjectMapper = new ObjectMapper();
prettyPrintObjectMapper.configure(SerializationFeature.INDENT_OUTPUT, true); //turn on
prettyPrintObjectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
String tmp1 = prettyPrintObjectMapper.writeValueAsString(myObject);
亲切的问候
安迪
推荐答案
使用-S
标志来格式化输出,如下所示:
Use the -S
flag to format the output like that:
-排序键/-S:
--sort-keys / -S:
按键顺序输出每个对象的字段.
Output the fields of each object with the keys in sorted order.
这篇关于我怎样才能让jq按字母顺序漂亮地打印json排序键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文