Skip to main content

sansJson

Tests PyPI version codecov

Your friendly neighborhood JSON sorter helper!

This package is meant to rival the native sort_keys option of the json package. sort_keys only re-orders the keys according to the alphanumeric priority. This method breaks down when internal components (such as lists) need to be re-ordered as well. To ensure consistency across the entire JSON object, as in the event of a hash, a recursive reordering of sortable components may be necessary. The following situations are covered:

Note:

  • Homogenous: All elements in a specific component are the same data type. (e.g. {'a': [1,2,3], 'b', [2,3,4], 'c': [3,4,5]})

  • Nonhomogenous: Each element in a specific component may be any of the supported JSON types. (e.g. {'a': [1, 'z', False], 0: [3,4,5]})

  • The default priority for nonhomogenous types is:

    1. null
    2. boolean
    3. number (int > float)
    4. string
    5. array
    6. object
  • Multi-level dict JSON (homogenous + nonhomogenous)

  • array JSON (homogenous + nonhomogenous)

    • All types except python object

The following cases are not supported:

  • python objects (i.e. classes)

Installation

pip install sansjson

How to use

>>> import sansjson
>>> to_sort = {'a': 0, 'g': [3, 1, 3, 2], 'c': 1, 'f': 2}
>>> sansjson.sort_pyobject(to_sort)
{'a': 0, 'c': 1, 'f': 2, 'g': [1, 2, 3, 3]}
>>> a = '{"z": 1, "a": {"12": true, "ef": ["a", 1, false], "ap": 0}}'
>>> sansjson.sort_json(a)
'{"a": {"12": true, "ap": 0, "ef": [false, 1, "a"]}, "z": 1}'

Release files for sansjson 0.3.0

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

Source distribution (sdist)

Source distribution for sansjson 0.3.0
File Size Uploaded
sansjson-0.3.0.tar.gz 23.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sansjson 0.3.0
File Interpreter ABI Platform
sansjson-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 43.9 kB

Release files / sansjson-0.3.0.tar.gz

Download URL sansjson-0.3.0.tar.gz
Size 23.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d0dbaf53a2b412e474c58e9097819020aec2c572fb973539f10590e322d2dfd7
BLAKE2b-256 checksum
How to use checksums
c2e35a5f8e33296514aa7d99706c768bc55a6db25c5b3202d569c010042cc44c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / sansjson-0.3.0-py3-none-any.whl

Download URL sansjson-0.3.0-py3-none-any.whl
Size 20.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d7acfc6fdbe1a5cb9ccff21ae114ba8c8d3f081e6884a282d014a5ed5af28958
BLAKE2b-256 checksum
How to use checksums
eb79b504830bf4208f0e01687217a600870d6728b86068b3c361e2eb1ae4be40
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

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