0


Recently, I got a problem while working with json in python. Actually that is about special symbols in json. The problem is defined with code below:

import json
app = {
       "text": "°"
       }
print(json.dumps(app, indent=2))

but giving this I get this:

{
  "text": "\u00b0"
}

Here the ° sign is replaced with \u00b0. But I want it to be exact as my input. How can I do it?

Thanks in advance.

1 Answer 1

2

According to https://pynative.com/python-json-encode-unicode-and-non-ascii-characters-as-is/, you want to set ensure_ascii=False:

>>> import json
>>> app={"text": "°"}
>>> print(json.dumps(app, indent=2, ensure_ascii=False))
{
  "text": "°"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.