pycharm如何对json文件格式化

1.json文件保存

将数据保存为json格式,并存储到.json文件中,需要注意键值对均用双引号,而非单引号。
样例如下所示:

{ "sampleDB": { "shippedVsCustDemand": [{ "CUSTOMER": "customer1", "ITEM": "desk", "SUPPLIEDQTY": 25, "DEMANDQTY": 3}, { "CUSTOMER": "customer1", "ITEM": "drawer", "SUPPLIEDQTY": 15, "DEMANDQTY": 12}, { "CUSTOMER": "customer1", "ITEM": "table", "SUPPLIEDQTY": 52, "DEMANDQTY": 6}, { "CUSTOMER": "customer2", "ITEM": "end table", "SUPPLIEDQTY": null, "DEMANDQTY": 5}, { "CUSTOMER": "customer2", "ITEM": "leg", "SUPPLIEDQTY": null, "DEMANDQTY": 10}, { "CUSTOMER": "customer2", "ITEM": "round table", "SUPPLIEDQTY": null, "DEMANDQTY": 15}, { "CUSTOMER": "customer3", "ITEM": "desk", "SUPPLIEDQTY": null, "DEMANDQTY": 21}, { "CUSTOMER": "customer3", "ITEM": "desk top", "SUPPLIEDQTY": null, "DEMANDQTY": 14}, { "CUSTOMER": "customer3", "ITEM": "end table", "SUPPLIEDQTY": 1, "DEMANDQTY": 7}], "totalManufItems": [{ "ITEM": "desk", "TOTALMANUFQTY": 25}, { "ITEM": "end table", "TOTALMANUFQTY": 155}]}}

2.组合键

在pycharm中,使用组合键ctrl+alt+L进行格式化。
效果如下所示:

{ "sampleDB": { "shippedVsCustDemand": [{ "CUSTOMER": "customer1", "ITEM": "desk", "SUPPLIEDQTY": 25, "DEMANDQTY": 3},
                                      { "CUSTOMER": "customer1", "ITEM": "drawer", "SUPPLIEDQTY": 15, "DEMANDQTY": 12},
                                      { "CUSTOMER": "customer1", "ITEM": "table", "SUPPLIEDQTY": 52, "DEMANDQTY": 6},
                                      { "CUSTOMER": "customer2", "ITEM": "end table", "SUPPLIEDQTY": null,
                                       "DEMANDQTY": 5},
                                      { "CUSTOMER": "customer2", "ITEM": "leg", "SUPPLIEDQTY": null, "DEMANDQTY": 10},
                                      { "CUSTOMER": "customer2", "ITEM": "round table", "SUPPLIEDQTY": null,
                                       "DEMANDQTY": 15},
                                      { "CUSTOMER": "customer3", "ITEM": "desk", "SUPPLIEDQTY": null, "DEMANDQTY": 21},
                                      { "CUSTOMER": "customer3", "ITEM": "desk top", "SUPPLIEDQTY": null,
                                       "DEMANDQTY": 14},
                                      { "CUSTOMER": "customer3", "ITEM": "end table", "SUPPLIEDQTY": 1, "DEMANDQTY": 7}],
              "totalManufItems": [{ "ITEM": "desk", "TOTALMANUFQTY": 25}, { "ITEM": "end table", "TOTALMANUFQTY": 155}]}}

参考:
[1] https://www.it610.com/article/1295759947937685504.htm

    原文作者:惜棠
    原文地址: https://blog.csdn.net/liuyi193146/article/details/111464443
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞