fujson


Namefujson JSON
Version 0.1.1 PyPI version JSON
download
home_page
SummaryFloat formatting control for JSON encoding.
upload_time2022-09-07 01:29:06
maintainer
docs_urlNone
author
requires_python>=3.5
licenseMIT License Copyright (c) [2022] [Stefaan Lippens] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
![PyPI](https://img.shields.io/pypi/v/fujson)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fujson)
![PyPI - Wheel](https://img.shields.io/pypi/wheel/fujson)
[![Tests](https://github.com/soxofaan/fujson/actions/workflows/test.yaml/badge.svg?branch=main)](https://github.com/soxofaan/fujson/actions/workflows/test.yaml)

# FuJSON: less decimals, more fuzzy JSON

FuJSON is a Python module that allows to control the 
formatting of floats when JSON encoding, 
typically to dial down the number of decimals.

It builds on the *standard library*'s `json.JSONEncoder`
and *monkey-patches* it to inject custom float formatting.


## Usage

Simple `dumps` call:

    >>> from fujson import dumps
    >>> dumps({"x": 1.23456789}, float_format=".2f")
    '{"x": 1.23}'

Reusable encoder:

    >>> from fujson import FuJsonEncoder
    >>> encoder = FuJsonEncoder(float_format=".2f")
    >>> encoder.encode({"x": 1.23456789})
    '{"x": 1.23}'
    >>> encoder.encode([1.1, 2.22, 3.333, 4.4444])
    '[1.10, 2.22, 3.33, 4.44]'

Do JSON dump with floats in scientific notation:

    >>> from fujson import FuJsonEncoder
    >>> encoder = FuJsonEncoder(float_format=".2e")
    >>> encoder.encode([.123, 0.0000123, 12345678.9])
    '[1.23e-01, 1.23e-05, 1.23e+07]'



            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "fujson",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "Stefaan Lippens <soxofaan@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/03/df/f189796b6cc2d1e59886a1fbcb5f30c8922a2b1b36ff8c5a72c064253c81/fujson-0.1.1.tar.gz",
    "platform": null,
    "description": "\n![PyPI](https://img.shields.io/pypi/v/fujson)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fujson)\n![PyPI - Wheel](https://img.shields.io/pypi/wheel/fujson)\n[![Tests](https://github.com/soxofaan/fujson/actions/workflows/test.yaml/badge.svg?branch=main)](https://github.com/soxofaan/fujson/actions/workflows/test.yaml)\n\n# FuJSON: less decimals, more fuzzy JSON\n\nFuJSON is a Python module that allows to control the \nformatting of floats when JSON encoding, \ntypically to dial down the number of decimals.\n\nIt builds on the *standard library*'s `json.JSONEncoder`\nand *monkey-patches* it to inject custom float formatting.\n\n\n## Usage\n\nSimple `dumps` call:\n\n    >>> from fujson import dumps\n    >>> dumps({\"x\": 1.23456789}, float_format=\".2f\")\n    '{\"x\": 1.23}'\n\nReusable encoder:\n\n    >>> from fujson import FuJsonEncoder\n    >>> encoder = FuJsonEncoder(float_format=\".2f\")\n    >>> encoder.encode({\"x\": 1.23456789})\n    '{\"x\": 1.23}'\n    >>> encoder.encode([1.1, 2.22, 3.333, 4.4444])\n    '[1.10, 2.22, 3.33, 4.44]'\n\nDo JSON dump with floats in scientific notation:\n\n    >>> from fujson import FuJsonEncoder\n    >>> encoder = FuJsonEncoder(float_format=\".2e\")\n    >>> encoder.encode([.123, 0.0000123, 12345678.9])\n    '[1.23e-01, 1.23e-05, 1.23e+07]'\n\n\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) [2022] [Stefaan Lippens]  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Float formatting control for JSON encoding.",
    "version": "0.1.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/soxofaan/fujson/issues",
        "Homepage": "https://github.com/soxofaan/fujson"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7fe766e07c2be02210ed5b019e639170e9c2b0f4fdf7e0d4528ad0480ccc6dcd",
                "md5": "14183c57866800bf9eadc4d87eeda82a",
                "sha256": "9e3e5eab03f6d8c4fac4877ae022b96c7b9d09089957c275306315182764e95b"
            },
            "downloads": -1,
            "filename": "fujson-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "14183c57866800bf9eadc4d87eeda82a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.5",
            "size": 3628,
            "upload_time": "2022-09-07T01:29:05",
            "upload_time_iso_8601": "2022-09-07T01:29:05.533585Z",
            "url": "https://files.pythonhosted.org/packages/7f/e7/66e07c2be02210ed5b019e639170e9c2b0f4fdf7e0d4528ad0480ccc6dcd/fujson-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "03dff189796b6cc2d1e59886a1fbcb5f30c8922a2b1b36ff8c5a72c064253c81",
                "md5": "ffccab605c736570e4ced041b87e34f4",
                "sha256": "46df837f4110eecdaf5195b5467e3cddba03869608252e0ae5ddf0cca7bf0bc6"
            },
            "downloads": -1,
            "filename": "fujson-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ffccab605c736570e4ced041b87e34f4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 2560,
            "upload_time": "2022-09-07T01:29:06",
            "upload_time_iso_8601": "2022-09-07T01:29:06.882402Z",
            "url": "https://files.pythonhosted.org/packages/03/df/f189796b6cc2d1e59886a1fbcb5f30c8922a2b1b36ff8c5a72c064253c81/fujson-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-09-07 01:29:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "soxofaan",
    "github_project": "fujson",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "fujson"
}
        
Elapsed time: 1.05079s