Detects places where JSON output can be minified
Project description
refurb-json-minify
A small plugin for Refurb aimed at minifying JSON outputs.
Why is this important?
JSON is a widely used format for data exchange, whether that be APIs talking over the internet, metadata being stored in a database, or config files stored on a user's filesystem. Although CPU and harddrive space is getting cheaper and cheaper, it isn't free, and being mindful of resources can lead to faster and more efficient programs.
Supported Checks
JMIN100
: Use separators
The json.dump
and
json.dumps
functions
allow for an optional separators
field which specifies what characters to use
for colons (:
) and commas (,
) in the JSON output. Normally there is whitespace
after these characters, but you can change this to use a more compact format.
Here is a simple example comparing the output of json.dumps()
with and without
separators
specified:
import json
data = {
"hello": "world",
"numbers": [1, 2, 3, 4],
}
a = json.dumps(data)
b = json.dumps(data, separators=(",", ":"))
print(f"{len(a)=}", f"{len(b)=}")
When we run this, we get:
len(a)=43 len(b)=37
By reducing the whitespace in our JSON output we where able to shave off 6 bytes, or about 16% in this example.
JMIN101
: Don't json.dump()
integers
Don't call json.dump()
on integers, use str()
instead since they share the
same representation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file refurb-json-minify-1.0.0.tar.gz
.
File metadata
- Download URL: refurb-json-minify-1.0.0.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.10 Linux/6.2.11-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55831084f18cb11bc5c3eb8f7a8c6b18cf85c2c6613aabc15ae3d78516de6cb8 |
|
MD5 | 3e059f8c46b2e9e65c015414712bd9e6 |
|
BLAKE2b-256 | 39b6d3c28f58c1bebde1d8181a344cbb6725f2a5205a9695e88d11d2e45b6c14 |
File details
Details for the file refurb_json_minify-1.0.0-py2.py3-none-any.whl
.
File metadata
- Download URL: refurb_json_minify-1.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.10 Linux/6.2.11-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18a821199fe8712fc574055d232233d46565fcf8dc041803ec522e429e8f1a8c |
|
MD5 | c24aa968eacb87a21b0782b644209a50 |
|
BLAKE2b-256 | ef15f10b009f5c4fafb1a2b56f6c16a0ba8dda2d41d38fac50fdc6dcfa87e603 |