python and true vs True

284 views
Skip to first unread message

J G

unread,
Jun 30, 2022, 3:11:56 PM6/30/22
to robotframework-users
Hi,

I have the following code:

${result} = Run Process acommand
${jsonresult}= evaluate ${result.stdout} json

The command returns json but when I call evaluate, I get

Evaluating expression '[...]' failed: NameError: name 'true' is not defined nor importable as module

Which is because the json has true and false values in it that are NOT properly capitalized:

{
  "up": true,
  "pending": false
}

There would be no problem if they were instead written like this:

{
  "up": True,
  "pending": False
}

The problem is that I do not control the application returning the json.

Is there a way to get the evaluate instruction to work regardless of the first letters of true and false not being capitalized?

Thanks

Hernandi Krammes

unread,
Jul 1, 2022, 2:17:06 PM7/1/22
to robotframework-users
I would execute a find/replace for all true/false events inside json and align the json :D

Tatu Aalto

unread,
Jul 4, 2022, 5:58:18 AM7/4/22
to prog...@gmail.com, robotframework-users
Hi

Converting string to Json is actually complex problem, instead of trying yourself to convert it you should either see does the library you are using already support it. If it does not not then using either Python json[1] or Robot Framework Json library [2] are good alternatives.

-Tatu

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/robotframework-users/044a94a5-7ff6-42da-814a-edc703a64dcfn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages