Python将JSON转储转换为具有内联数组的文件

时间:2018-04-11 07:51:06

标签: python json dictionary

我是这样的一个词:

{'#charliehebdo_attack_paris-20150107_072714-20150107_085144': {'OWA_max': 0.57489770154717, 'features': [0.57489770154717, 0.3087177211515125, 0.30136460335548143, 0.2400354295837024, 0.23378076062639822, 0.19642857142857142, 0.09542625404898004, 0.08767123287671233, 0.07523302263648468, 0.0510980171038674, 0.04591177164554867, 0.031815346225826574, 0.01024247491638796, 0.0014344334495534816, 0.0], 'truth': 1.0, 'weights': [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}, ...

当我将其转储到JSON文件时:

json.dump(dict, file, indent = 4)

我得到这种JSON格式:

{
"#charliehebdo_attack_paris-20150107_072714-20150107_085144": {
    "OWA_max": 0.57489770154717,
    "features": [
        0.57489770154717,
        0.3087177211515125,
        0.30136460335548143,
        0.2400354295837024,
        0.23378076062639822,
        0.19642857142857142,
        0.09542625404898004,
        0.08767123287671233,
        0.07523302263648468,
        0.0510980171038674,
        0.04591177164554867,
        0.031815346225826574,
        0.01024247491638796,
        0.0014344334495534816,
        0.0
    ],
    "truth": 1.0,
    "weights": [
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0
    ]
}, ...

但是我希望像这样内联数组:

{
"#charliehebdo_attack_paris-20150107_072714-20150107_085144": {
"OWA_max": 0.57489770154717,
"features": [0.57489770154717, 0.3087177211515125,0.30136460335548143,0.2400354295837024,...
"truth": 1.0,
"weights": [1 0, 0, 0, 0, ...

如何让这种格式更好地查看数据?

0 个答案:

没有答案