Skip to main content

Overwrite the default behavior of json.dumps to ensure_ascii=False

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json-direct-1.0.1.tar.gz (2.0 kB view details)

Uploaded Source

File details

Details for the file json-direct-1.0.1.tar.gz.

File metadata

  • Download URL: json-direct-1.0.1.tar.gz
  • Upload date:
  • Size: 2.0 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for json-direct-1.0.1.tar.gz
Algorithm Hash digest
SHA256 02910ece19f288f084743c572f76f4415286277a0377b98510bfc79579ddc270
MD5 16029ced30b8e2f1b6021601d6962d1d
BLAKE2b-256 1b4a5a78c32a632e61e399abfc4369673753978fd034d6e7bc3818e5883769cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page