Unable to put json string into dictionary as a string

I am trying to create a dictionary with some json content I want to try and the corresponding return status. It looks like this:

@{jsonlines}= Create Dictionary {"name": "RobotTestUser","firstname": "Rob","lastname": "Mc Robot","email": "mcrobot@email.de","roleid": 0} 400

(I also tried the syntax with =, didnt work either.)

The resulting dictionary does not have the 400 as a value, it just disappears.

Obviously it converts the “key” to a dictionary and ignores the rest.

So what am I doing wrong? I also tried escaping that json string, with , ‘’’
, " and whatever else came to mind. Its still being converted. I just want it to take it as a string and put it into the key.

Thx for any help or advice!

Hi @skyflash,

I’m curious where you were expecting the 400 to appear? As a Key or as a Value?

Let’s break this down:

@{jsonlines}= Create Dictionary

You’ve called Create Dictionary and assigned it to a list variable not a dictionary variable, not ideal but robot framework / python can handle this and convert the list into a dictionary

next i’'ll reformat your data

{
    "name": "RobotTestUser",
    "firstname": "Rob",
    "lastname": "Mc Robot",
    "email": "mcrobot@email.de",
    "roleid": 0
} 400

As you can see you placed the 400 after the } outside the dictionary of key/value pairs, this is why I’m not sure how you were expecting the 400 to appear.

Also that JSON style dictionary data format is not mentioned in the documentation for Create Dictionary, so I’m not sure if its supported.

If you were expecting the 400 as a value what should it’s key be? “roleid”?

If you were expecting the 400 as a key what should it’s value be? NULL?

Hopefully one of these will give you what you were wanting:

	&{jsonlines1}= 	Create Dictionary 	name 	RobotTestUser 	firstname 	Rob 	lastname 	Mc Robot 	email 	mcrobot@email.de 	roleid 	0 	400 	${EMPTY}

	&{jsonlines1}= 	Create Dictionary 	name=RobotTestUser 	firstname=Rob 	lastname=Mc Robot 	email=mcrobot@email.de 	roleid=0 	400=${EMPTY}

	&{jsonlines1}= 	Create Dictionary 	name 	RobotTestUser 	firstname 	Rob 	lastname 	Mc Robot 	email 	mcrobot@email.de 	roleid 	0 	newkey 	400

	&{jsonlines1}= 	Create Dictionary 	name=RobotTestUser 	firstname=Rob 	lastname=Mc Robot 	email=mcrobot@email.de 	roleid=0 	newkey=400

Dave.

1 Like