Skip to main content

json-direct

Introduction

json-direct is a package that overwrites the original json.dumps to make the default value of ensure_ascii to False. You only need to import json_direct and do nothing else, and then you can use json.dumps as normal and get the human-readable JSON string. You don't need to input ensure_ascii=False every time in your code.

Installation

pip3 install json-direct

Usage

import json_direct
import json

print(json.dumps({'测试': "テスト,테스트"}))

This will print {"测试": "テスト,테스트"}, instead of {"\u6d4b\u8bd5": "\u30c6\u30b9\u30c8\uff0c\ud14c\uc2a4\ud2b8"}.

Why

The default behavior of json.dumps (use \uxxxx to escape non-ascii words) leads to a lot of serious problems, such as incompatibility, unreadability, difference from expectation, etc.

For example, if you use json.dumps({'测试': "テスト,테스트"}), you will get {"\u6d4b\u8bd5": "\u30c6\u30b9\u30c8\uff0c\ud14c\uc2a4\ud2b8"}. This is not what you want. You want {"测试": "テスト,테스트"}.

The aim of this project is to increase the compatibility of code, and also ease the usage of json.dumps.

License

This project is under MIT License. You can use it freely.

Metadata

Release files for json-direct 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for json-direct 1.0.1
File Size Uploaded
json-direct-1.0.1.tar.gz 2.0 kB Details

Release files / json-direct-1.0.1.tar.gz

Download URL json-direct-1.0.1.tar.gz
Size 2.0 kB
Tags Source
SHA-256 checksum
How to use checksums
02910ece19f288f084743c572f76f4415286277a0377b98510bfc79579ddc270
BLAKE2b-256 checksum
How to use checksums
1b4a5a78c32a632e61e399abfc4369673753978fd034d6e7bc3818e5883769cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/7.1.0 pkginfo/1.11.1 requests/2.32.2 requests-toolbelt/1.0.0 tqdm/4.66.4 CPython/3.11.9

Release history Release notifications | RSS feed

This release

1.0.1 This release

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page