从文件中读取JSON,使用选定的值格式化输出

时间:2014-09-06 15:37:39

标签: json format

说我在我的calendar.json文件中有以下内容:

{
    "dates":[{
        "id": "1",
        "month_name": "january",
        "day_name": "wednesday",
        "day": "1",
        "month": "1",
        "holiday": "Some Holiday Label",
        },
        {
        "id": "2",
        "month_name": "january",
        "day_name": "thursday",
        "day": "2",
        "month": "1",
        "holiday": "Some Other Holiday Label",
        }
]}

我想在另一个文件中得到这样的结果:

holiday.sr-RS1.name=Some Holiday Label # here would be the data extracted from holiday field of the above `json`
holiday.sr-RS1.date=20140908 # here would be the data extracted from day,month field
                             # ,and manually added year to form date in that specific format

这样格式化输出当然不是问题,我的问题是什么 我应该用最简单的方式来完成这个,我试过python但是 一些奇怪的问题无法读取json文件,因为 Unexpected UTF-8 BOM错误。我不依赖于任何特定的编程 语言,我只是对解析这个JSON并输出它的最好方法感兴趣 以我需要的格式写入文件。

0 个答案:

没有答案