Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong character encoding for UTF-8 #59

Open
luprochazka-cen63872 opened this issue Oct 18, 2023 · 1 comment
Open

Wrong character encoding for UTF-8 #59

luprochazka-cen63872 opened this issue Oct 18, 2023 · 1 comment

Comments

@luprochazka-cen63872
Copy link

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**)`
@abelikt
Copy link

abelikt commented Nov 20, 2023

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:
#60

Regards,
Michael

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants