A Python one-liner that pretty prints json. Do not escape Japanese.

"Ensure_ascii = False" is the miso.

sh


$ echo '{"one":1, "two":2, "Japanese":"Ah ah"}' | python -c 'import sys,json;print json.dumps(json.loads(sys.stdin.read()),indent=4,ensure_ascii=False)'

{
    "Japanese": "Ah ah", 
    "two": 2, 
    "one": 1
}

I really want to use python -mtool.json as below, but the Japanese part is escaped.

sh


$ echo '{"one":1, "two":2, "Japanese":"Ah ah"}' | python -mjson.tool                                                                                    
{
    "one": 1,
    "two": 2,
    "\u65e5\u672c\u8a9e": "\u3042\u3042\u3042"
}

Recommended Posts

A Python one-liner that pretty prints json. Do not escape Japanese.
How to not escape Japanese when dealing with json in python
Miscellaneous notes that I tried using python for the matter
Try to understand Python self
I understand Python in Japanese!
A Python one-liner that pretty prints json. Do not escape Japanese.
Tips: [Python] Extract only lines that do not contain a specific string
Tips: [Python] Extract only lines that do not contain a specific string
Collect Japanese tweets that do not include images, URLs or replies in Python
[Python] Extracts data frames that do not match a specific column with other data frames of Pandas
A set of script files that do wordcloud in Python3
Python list is not a list
[Python / Django] Create a web API that responds in JSON format
A record that GAMEBOY could not be done in Python. (PYBOY)
A special Python codec that seems to know but does not know
[Python] Do not put Japanese in the path used by OpenCV
Do you need a Python re.compile?
A pretty sloppy Python error solution
A note that prints numpy.array nicely
What to do if there is a decimal in python json .dumps
Introducing a library that was not included in pip on Python / Windows
I tried to develop a Formatter that outputs Python logs in JSON
A general-purpose tool that programmers who do not know this will lose