Skip to content

Commit

Permalink
Example of working with large integers
Browse files Browse the repository at this point in the history
  • Loading branch information
nineteendo committed Sep 14, 2024
1 parent b0771d5 commit 311b179
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
29 changes: 29 additions & 0 deletions docs/source/how-to.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,32 @@ After installing :pypi:`multidict`, it can be used like this:
>>> decoder = json.Decoder(allow=jsonyx.allow.DUPLICATE_KEYS)
>>> from_json(decoder.loads('{"key": "value 1", "key": "value 2"}'))
<MultiDict('key': 'value 1', 'key': 'value 2')>

Disabling the integer string conversion length limit
----------------------------------------------------

.. tab:: without classes

>>> import jsonyx as json
>>> from sys import set_int_max_str_digits
>>>
>>>
>>> set_int_max_str_digits(0)
>>> json.loads("9" * 5_000) == 10 ** 5_000 - 1
True
>>> len(json.dumps(10 ** 5_000))
5002

.. tab:: with classes

>>> import jsonyx as json
>>> from sys import set_int_max_str_digits
>>> decoder = json.Decoder()
>>> encoder = json.Encoder()
>>> set_int_max_str_digits(0)
>>> decoder.loads("9" * 5_000) == 10 ** 5_000 - 1
True
>>> len(encoder.dumps(10 ** 5_000))
5002

See :ref:`int_max_str_digits` for more information.
1 change: 0 additions & 1 deletion src/jsonyx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (C) 2024 Nice Zombies
"""Customizable JSON library for Python."""
# TODO(Nice Zombies): add release date in changelog
# TODO(Nice Zomebies): explain how to use large numbers
# TODO(Nice Zombies): update raised exceptions
from __future__ import annotations

Expand Down

0 comments on commit 311b179

Please sign in to comment.