Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从文件读取JSON,用选定值格式化输出_Json_Format - Fatal编程技术网

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

从文件读取JSON,用选定值格式化输出,json,format,Json,Format,假设我在calendar.json文件中有以下内容: { "dates":[{ "id": "1", "month_name": "january", "day_name": "wednesday", "day": "1", "month": "1", "holiday": "Some Holiday Label", }, { "id": "2"

假设我在
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
文件,因为
意外的UTF-8 BOM
错误。我不喜欢任何特定的编程 语言,我只是对解析这个JSON并输出它的最佳方式感兴趣
以我需要的格式写入文件。

看看这里,如何避免Python中的BOM错误:这很有帮助。谢谢。