如何在robotframework中使用缩进以json格式存储响应



我正在尝试将API的响应存储在带有缩进的JSON文件中。但当我尝试时,我遇到了一个以JSON格式存储的问题。

有人能帮我写这个机器人框架代码吗?

Robotcode.robot

${response} =  [{'id': u'a123', 'tags': [{'name': u'App', 'value': u'12378'}]}]
${req_json}    Json.Dumps    ${response}     indent=3
Create File  results//test.json  ${req_json}

运行时出错:

TypeError:无法将序列与类型为"unicode"的非int相乘

我预期:

[
{
"name": "a123", 
"tags": []
}, 
{
"name": "Stack001", 
"tags": [
{
"name": "App", 
"value": "12378"
}, 
]}}]

缩进格式的东西如何使用机器人框架实现这一点?

我使用python实现了。

python code
def writeJson(data,type):
with open(type, "w") as write_file:
json.dump(data, write_file, indent=3)
robot code
writeJson  ${response}   results//test.json

最新更新