Skip to main content

Your friendly neighborhood JSON sorter helper

Project description

sansJson

Tests PyPI version

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 dict or object

The following cases are not supported:

  • array of dict JSON (i.e. any list of objects)
  • 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(to_sort)
{'a': 0, 'c': 1, 'f': 2, 'g': [1, 2, 3, 3]}

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.0.4.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distribution

sansjson-0.0.4-py3-none-any.whl (2.9 kB view hashes)

Uploaded Python 3

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