Skip to main content

Your friendly neighborhood JSON sorter helper

Project description

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}'

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

sansjson-0.3.0.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

sansjson-0.3.0-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file sansjson-0.3.0.tar.gz.

File metadata

  • Download URL: sansjson-0.3.0.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for sansjson-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d0dbaf53a2b412e474c58e9097819020aec2c572fb973539f10590e322d2dfd7
MD5 e91d630dce2245a803f574209dd0a882
BLAKE2b-256 c2e35a5f8e33296514aa7d99706c768bc55a6db25c5b3202d569c010042cc44c

See more details on using hashes here.

File details

Details for the file sansjson-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: sansjson-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for sansjson-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d7acfc6fdbe1a5cb9ccff21ae114ba8c8d3f081e6884a282d014a5ed5af28958
MD5 e07c638f9fd3e5e7b2c87e7c9ed3ec16
BLAKE2b-256 eb79b504830bf4208f0e01687217a600870d6728b86068b3c361e2eb1ae4be40

See more details on using hashes here.

Supported by

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