JSON 手动生成有效,但通过 json.dumps 创建无效,即使输出看起来完全相同

JSON generated manually works, but created through json.dumps does not work even if output seems to be exactly same

我正在通过 Python 库 marketo-rest-python 使用 Marketo API。我可以创建潜在客户并通过以下基本代码更新它们:

leads = [{"email":"joe@example.com","firstName":"Joe"},{"email":"jill@example.com","firstName":"Jill"}]
lead = mc.execute(method='create_update_leads', leads=leads, action='createOnly', lookupField='email', 
                asyncProcessing='false', partitionName='Default')

当我以编程方式创建这个 "leads" JSON 对象时

leads = []

lead = {}
lead['email'] = "joe@example.com"
lead['firstName'] = "Joe"
leads.append(lead)

lead = {}
lead['email'] = "jill@example.com"
lead['firstName'] = "Jill"
leads.append(lead)

json_leads = json.dumps(leads, separators=(',', ':'))

print(json_leads)

然后输出在 Microsoft Azure Databricks 中完全相同,但是 Marketo 系统 returns 我 609-> Invalid JSON.

我的输出看起来像

[{"email":"joe@example.com","firstName":"Joe"},{"email":"jill@example.com","firstName":"Jill"}]

和示例中的一模一样。当我使用示例 JSON 代码行时它有效,但我自己生成的 JSOn 无效。

有人知道这是什么吗?我在 Microsoft Azure Databricks 中使用 Python。

我相信你不需要调用json.dumps,直接调用

leads = []

lead = {}
lead['email'] = "joe@example.com"
lead['firstName'] = "Joe"
leads.append(lead)

lead = {}
lead['email'] = "jill@example.com"
lead['firstName'] = "Jill"
leads.append(lead)

lead = mc.execute(method='create_update_leads', leads=leads, action='createOnly', 
lookupField='email', asyncProcessing='false', partitionName='Default')