robotframework-jsonlibrary
robotframework-jsonlibrary copied to clipboard
Wrong character encoding for UTF-8
Function convert_json_to_string returns wrong encoding if you use UTF-8. I have workaround:
` @staticmethod def convert_json_to_string(json_object): """Convert JSON object to string
Arguments:
- json_object: json as a dictionary object.
Return new json_string
Examples:
| ${json_str}= | Convert JSON To String | ${json_obj} |
"""
return json.dumps(json_object, **ensure_ascii=False**)`
Hi,
indeed, for some reason we are getting Utf-16 instead of Utf-8 encoded data from json.dumps.
Like this German umlaut: json.dumps({"test":"über"}) results in '{"test": "\\u00fcber"}'.
Here is a test for this issue:
*** Settings ***
Library JSONLibrary
*** Test Cases ***
Test_Conversion short
${data} = Set Variable "{'test':'über'}"
${json} = Convert String To Json ${data}
${string} = Convert Json To String ${json}
# Issue: "{'test':'\u00fcber'}" != "{'test':'über'}"
Should Be Equal ${string} ${data}
I created a PR here as a workaround to forward the ensure_ascii parameter to json.dumps: https://github.com/robotframework-thailand/robotframework-jsonlibrary/pull/60
Regards, Michael