Python构建了混合类型的JSON

Python构建了混合类型的JSON,python,json,Python,Json,实际上,我从python对象开始构建Json对象 我的出发点是: responseMsgObject = {'Version': 1, 'Id': 'xc23', 'Local': "US" 'Type': "Test", 'Message' : "Message body" }

实际上,我从python对象开始构建Json对象

我的出发点是:

    responseMsgObject = {'Version': 1,
                         'Id': 'xc23',
                         'Local': "US"
                         'Type': "Test",
                         'Message' : "Message body" }

    responseMsgJson = json.dumps(responseMsgObject, sort_keys=False )
每件事都是可行的,但现在我需要把下面的JSON放到“Message”字段中

我构建了许多其他json(但更简单),但这个json给我带来了麻烦


谢谢你的帮助。

试着用true works替换true对我来说很好

import json
responseMsgObject = {
    'Version': 1,
    'Id': 'xc23',
    'Local': "US",
    'Type': "Test",
    'Message': {
        "DepID": "001",
        "Assets": [{
            "Type": "xyz",
            "Text": [
                "abc",
                "def"
            ],
            "Metadata": {
                "V": "1",
                "Req": True,
                "Other": "othervalue"
            },
            "Check": "refdw321"
        }, {
            "Type": "jkl",
            "Text": [
                "ghi"
            ],
            "Metadata": {
                "V": "6"
            },
            "Check": "345ghsdan4"
        }]
    }
}

responseMsgJson = json.dumps(responseMsgObject, sort_keys=False )
print("responseMsgJson", responseMsgJson)

那么,问题出在哪里?请编辑问题以提供一个详细的说明,特别包括您正在处理的部分和相关的堆栈跟踪(如果有)。我更新问题,我需要将此json放入另一个json中。具体到“Message”字段中,我将第一个json中的消息体替换为第二个json是否正确?{“Version”:1,“Id”:“xc23”,“Local”:“US”,“Type”:“Test”,“Message”:这里是第二个json}对不起,我没有深入阅读。基本上,我可以创建一个包含数组和moch的python对象吗?然后转换成JSON?如果值可以转换成字符串,你可以这样做
import json
responseMsgObject = {
    'Version': 1,
    'Id': 'xc23',
    'Local': "US",
    'Type': "Test",
    'Message': {
        "DepID": "001",
        "Assets": [{
            "Type": "xyz",
            "Text": [
                "abc",
                "def"
            ],
            "Metadata": {
                "V": "1",
                "Req": True,
                "Other": "othervalue"
            },
            "Check": "refdw321"
        }, {
            "Type": "jkl",
            "Text": [
                "ghi"
            ],
            "Metadata": {
                "V": "6"
            },
            "Check": "345ghsdan4"
        }]
    }
}

responseMsgJson = json.dumps(responseMsgObject, sort_keys=False )
print("responseMsgJson", responseMsgJson)