Python 如何操作给定json输入文件中的数据并将其保存为所需格式

Python 如何操作给定json输入文件中的数据并将其保存为所需格式,python,json,Python,Json,我有一个文件input.txt,它实际上是一个逗号分隔的列表 嵌入JSON结构中的字符串,其中 由管道(|)分隔 请注意,last operation列是如何在所需的输出中拆分为LastOperation和OperationTime的 在这种情况下,请使用两个空格作为字段分隔符/分隔符 输入json文件为: '{ "info": { "status": "succ", "type": "command" }, "data": {

我有一个文件
input.txt
,它实际上是一个逗号分隔的列表 嵌入JSON结构中的字符串,其中 由管道(
|
)分隔

请注意,
last operation
列是如何在所需的输出中拆分为LastOperation和OperationTime的

在这种情况下,请使用两个空格作为字段分隔符/分隔符

输入json文件为:

'{
    "info": {
        "status": "succ",
        "type": "command"
    },
    "data": {
        "list": [
            "CommQ data set name: test.ttq1.tt2.tt3",
            "               size: 19169280 bytes",
            "               used: 537320 bytes",
            "Destination name|status|     last operation     | sent |queued|address",
            "testifLAPPXDgx01    |active|Send OK  14.02.22 07 SEP|    26|     0|testifLAPPXDgx01..test.server ",
            "testifLAPPXDgx02    |active|Send OK  14.02.22 07 SEP|    12|     0|testifLAPPXDgx02..test.server ",
            "testifLAPPXDgx30    |active|Send OK  14.01.49 07 SEP|     7|     0|testifLAPPXDgx30..test.server ",
            "testifLAPPXDgx40    |active|Send OK  14.01.49 07 SEP|     7|     0|testifLAPPXDgx40..test.server ",

            "1105 senders, 0 quiesced"
        ]
    }
}'
所需输出:

[
    {
        "Destination": "testifLAPPXDgx01",
        "Status": "active",
        "LastOperation": "SEND OK",
        "OperationTime": "14.01.49 07 SEP",
        "Sent": 7,
        "Queued": 0,
        "Address": "testifLAPPXDgx01..test.server"
    },
    {
       "Destination": "testifLAPPXDgx02",
        "Status": "active",
        "LastOperation": "SEND OK",
        "OperationTime": "14.02.22 07 SEP",
        "Sent": 26,
        "Queued": 0,
        "Address": "testifLAPPXDgx02..test.server"
    }
]

实际上,您的问题与JSON没有什么关系:您正在寻找一种方法来解析您的_JSON.data.list的内容。只需在
|
上拆分每一行,然后(如果你得到正确的片段数),在两个空格上拆分你的第三列。我无法做到这一点,这会给应用循环带来麻烦。如果你能为我提供解决方案,我将非常感谢你,因为作为一项任务,这对我来说至关重要。请向我提供代码。显示您迄今为止所尝试的,解释它如何无法按预期工作,您将更有可能获得帮助。