Opening a file with the encoding set to utf-8, and then passing that file to the .to_json
function fixes the problem:
with open('df.json', 'w', encoding='utf-8') as file:
df.to_json(file, force_ascii=False)
gives the correct:
{"0":{"0":"τ","1":"π"},"1":{"0":"a","1":"b"},"2":{"0":1,"1":2}}
Note: it does still require the force_ascii=False
argument.
Related Contents:
- Saving UTF-8 texts with json.dumps as UTF-8, not as a \u escape sequence
- UnicodeDecodeError when reading CSV file in Pandas with Python
- Split / Explode a column of dictionaries into separate columns with pandas
- How to get string objects instead of Unicode from JSON?
- JSON to pandas DataFrame
- Loading a file with more than one line of JSON into Pandas
- Efficient way to unnest (explode) multiple list columns in a pandas DataFrame
- Reading multiple JSON records into a Pandas dataframe
- How to flatten a pandas dataframe with some columns as json?
- UnicodeDecodeError when reading CSV file in Pandas
- Python: Read several json files from a folder
- Pandas read nested json
- pandas read_json: “If using all scalar values, you must pass an index”
- Convert numpy type to python
- How to extract multiple JSON objects from one file?
- pandas json_normalize with very nested json
- Convert Pandas Dataframe to nested JSON
- Nested Json to pandas DataFrame with specific format
- Pandas dataframe to json without index
- How to invert the x or y axis
- Convert Pandas column containing NaNs to dtype `int`
- Find element’s index in pandas Series
- Pandas DataFrame column to list [duplicate]
- String to Dictionary in Python [duplicate]
- Python, Unicode, and the Windows console
- How to select rows in a DataFrame between two values, in Python Pandas?
- Pandas groupby cumulative sum
- Give column name when read csv file pandas
- Get last “column” after .str.split() operation on column in pandas DataFrame
- How to send requests with JSON in unit tests
- Add multiple empty columns to pandas DataFrame
- sending NaN in json
- Pandas – Filtering None Values
- Pandas: Convert Timestamp to datetime.date
- AttributeError: ‘Series’ object has no attribute ‘reshape’
- How to fix ”UnicodeDecodeError: ‘charmap’ codec can’t decode byte 0x9d in position 29815: character maps to ”?
- Pandas – Strip white space
- pandas – find first occurrence
- How to open my files in data_folder with pandas using relative path?
- How to group DataFrame by a period of time?
- Upgrade version of Pandas
- python pandas replacing strings in dataframe with numbers
- List of objects to JSON with Python
- how to read json object in python [duplicate]
- Selecting columns from pandas MultiIndex
- pandas dataframe str.contains() AND operation
- Why does base64.b64encode() return a bytes object?
- Use None instead of np.nan for null values in pandas DataFrame
- Pandas Timedelta in months
- Get unique values from index column in MultiIndex