How to not escape Japanese when dealing with json in python

Encode

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import json

dict = {"hello": "Japanese"}
text = json.dumps(dict, sort_keys=True, ensure_ascii=False, indent=2)
with open("utf8.json", "w") as fh:
    fh.write(text.encode("utf-8"))

Decode

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import print_function
import json

with open("utf8.json") as fh:
    js = json.loads(fh.read(), "utf-8")
    print(js["hello"])

Recommended Posts

How to not escape Japanese when dealing with json in python
Japanese output when dealing with python in visual studio
How to handle Japanese in Python
How to work with BigQuery in Python
How to display python Japanese with lolipop
How to enter Japanese with Python curses
[REAPER] How to play with Reascript in Python
How to create a JSON file in Python
Precautions when dealing with control structures in Python 2.6
Character encoding when dealing with files in Python 3
How to use tkinter with python in pyenv
[Python] How to handle Japanese characters with openCV
How to convert / restore a string with [] in python
How to do hash calculation with salt in Python
Explain in detail how to make sounds with python
How to run tests in bulk with Python unittest
Precautions when dealing with ROS MultiArray types in Python
How to access with cache when reading_json in pandas
How to convert JSON file to CSV file with Python Pandas
How to exit when using Python in Terminal (Mac)
How to develop in Python
How to handle JSON in Ruby, Python, JavaScript, PHP
Problem not knowing parameters when dealing with Blender from Python
How to extract any appointment in Google Calendar with Python
How to not load images when using PhantomJS with Selenium
[Introduction to Udemy Python 3 + Application] 36. How to use In and Not
Things to keep in mind when using Python with AtCoder
Things to keep in mind when using cgi with python.
How to log in to AtCoder with Python and submit automatically
[Python] How to do PCA in Python
Python: How to use async with
How to collect images in Python
How to use SQLite in Python
[Introduction to Python] How to parse JSON
How to get started with Python
How to use Mysql in python
How to wrap C in Python
How to use ChemSpider in Python
How to use FTP with Python
How to use PubChem in Python
How to calculate date with python
Until dealing with python in Atom
How to deal with python installation error in pyenv (BUILD FAILED)
A Python one-liner that pretty prints json. Do not escape Japanese.
How to create a heatmap with an arbitrary domain in Python
How to use python put in pyenv on macOS with PyCall
How to deal with errors when installing Python and pip with choco
How to display legend marks in one with Python 2D plot
How to calculate "xx time" in one shot with Python timedelta
[Introduction to Python] How to use class in Python?
Try logging in to qiita with Python
How to access environment variables in Python
How to dynamically define variables in Python
How to do R chartr () in Python
[Itertools.permutations] How to put permutations in Python
Tips for dealing with binaries in Python
Convert Excel data to JSON with python
How to get a stacktrace in python
How to display multiplication table in python
How to extract polygon area in Python
How to use Japanese with NLTK plot