Mia
Mia

Reputation: 448

How to store response in json format using indent in robotframework?

I am trying to store the response from an API in a JSON File with indentation. But when I try I am facing an issue on storing in the JSON FORMAT.

Can anybody help me with this robot framework code?

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}

ERROR while Running:

TypeError: can't multiply sequence by non-int of type 'unicode'

I expected:

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

something in indentation format How can I achieve this using robot framework?

Upvotes: 0

Views: 743

Answers (1)

Mia
Mia

Reputation: 448

I achieved using 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

Upvotes: 1

Related Questions