从列表中的jsons创建python嵌套json

时间:2016-03-20 07:54:10

标签: python json

我有一个字符串列表(jsons)。 pprint.pprint(jsondump)给出:

[
    '{"Parent\'s Name:": "xx", "School Award Won:": "xx", "Rank:": "862"}',
    '{"Parent\'s Name:": "xx", "School Award Won:": "xx", "Rank:": "872"}',
    '{"Parent\'s Name:": "xx", "School Award Won:": "xx", "Rank:": "333"}'
]

我想将它转换为单个json,如:

{
    {"Parent\'s Name:": "xx", "School Award Won:": "xx", "Rank:": "862"},
    {"Parent\'s Name:": "xx", "School Award Won:": "xx", "Rank:": "872"},
    {"Parent\'s Name:": "xx", "School Award Won:": "xx", "Rank:": "333"}
}

我知道这不是有效的json,有人能知道怎么做?

1 个答案:

答案 0 :(得分:0)

  1. json.dumps(' [' +',' .join(your_list)+']') 在这里,您创建一个字符串,以括号开头和结尾,如JSON列表,并包含所有字符串,以逗号分隔。创建后 - 转储到python列表。
  2. [json.dumps(el)for your in your_list] 在这里,您将每个元素转储到python对象,并通过list comprehensions将结果转换为python列表