python json是什么_Python正确的JSON格式是什么?

需要将数据发布到REST API。一个字段incident_type需要以下面的JSON格式传递(必须包含括号,不能只是大括号):"incident_type_ids": [{

"name": "Phishing - General"

}],

当我尝试在我的代码中强制执行此操作时,不正确。通常会有一些额外的引号转义(例如output "incident_type_ids": "[\\"{ name : Phishing - General }\\"]":),这是因为我在incident type变量中对JSON数据进行了双重编码以强制添加括号(在第6行中,此后被注释掉):#incident variables

name = 'Incident Name 2'

description = 'This is the description'

corpID = 'id'

incident_type = '{ name : Phishing - General }'

#incident_type = json.dumps([incident_type])

incident_owner = 'Security Operations Center'

payload = {

'name':name,

'discovered_date':'0',

'owner_id':incident_owner,

'description':description,

'exposure_individual_name':corpID,

'incident_type_ids':incident_type

}

body=json.dumps(payload)

create = s.post(url, data=body, headers=headers, verify=False)

因为我注释掉了这一行,所以无法得到incident_type需要的格式(括号)。

如何incident_type在最终的格式中获得正确格式的变量payload?

输入手动使用产品的交互式REST API工作:{

"name": "Incident Name 2",

"incident_type_ids": [{

"name": "Phishing - General"

}],

"description": "This is the description",

"discovered_date": "0",

"exposure_individual_name": "id",

"owner_id": "Security Operations Center"

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值