{"id":13477211,"url":"https://github.com/ijl/orjson","last_synced_at":"2025-05-12T22:34:35.465Z","repository":{"id":37781742,"uuid":"158618772","full_name":"ijl/orjson","owner":"ijl","description":"Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy","archived":false,"fork":false,"pushed_at":"2025-04-29T22:22:53.000Z","size":5631,"stargazers_count":6867,"open_issues_count":3,"forks_count":241,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-05-05T17:21:41.326Z","etag":null,"topics":["dataclasses","datetime","deserialization","json","numpy","pyo3","python","rust","serialization"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ijl.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-11-21T23:43:14.000Z","updated_at":"2025-05-05T10:30:16.000Z","dependencies_parsed_at":"2022-07-10T14:46:44.911Z","dependency_job_id":"9e701081-9001-42b3-8292-400149f8412e","html_url":"https://github.com/ijl/orjson","commit_stats":{"total_commits":687,"total_committers":25,"mean_commits":27.48,"dds":"0.055312954876273634","last_synced_commit":"8ece0d4bec4553934aa5883c15efdc3ccc49515f"},"previous_names":[],"tags_count":139,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ijl%2Forjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ijl%2Forjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ijl%2Forjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ijl%2Forjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ijl","download_url":"https://codeload.github.com/ijl/orjson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253141421,"owners_count":21860538,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dataclasses","datetime","deserialization","json","numpy","pyo3","python","rust","serialization"],"created_at":"2024-07-31T16:01:39.478Z","updated_at":"2025-05-12T22:34:35.408Z","avatar_url":"https://github.com/ijl.png","language":"Python","readme":"# orjson\n\norjson is a fast, correct JSON library for Python. It\n[benchmarks](https://github.com/ijl/orjson?tab=readme-ov-file#performance) as the fastest Python\nlibrary for JSON and is more correct than the standard json library or other\nthird-party libraries. It serializes\n[dataclass](https://github.com/ijl/orjson?tab=readme-ov-file#dataclass),\n[datetime](https://github.com/ijl/orjson?tab=readme-ov-file#datetime),\n[numpy](https://github.com/ijl/orjson?tab=readme-ov-file#numpy), and\n[UUID](https://github.com/ijl/orjson?tab=readme-ov-file#uuid) instances natively.\n\n[orjson.dumps()](https://github.com/ijl/orjson?tab=readme-ov-file#serialize) is\nsomething like 10x as fast as `json`, serializes\ncommon types and subtypes, has a `default` parameter for the caller to specify\nhow to serialize arbitrary types, and has a number of flags controlling output.\n\n[orjson.loads()](https://github.com/ijl/orjson?tab=readme-ov-file#deserialize)\nis something like 2x as fast as `json`, and is strictly compliant with UTF-8 and\nRFC 8259 (\"The JavaScript Object Notation (JSON) Data Interchange Format\").\n\nReading from and writing to files, line-delimited JSON files, and so on is\nnot provided by the library.\n\norjson supports CPython 3.9, 3.10, 3.11, 3.12, 3.13, and 3.14.\n\nIt distributes amd64/x86_64/x64, i686/x86, aarch64/arm64/armv8, arm7,\nppc64le/POWER8, and s390x wheels for Linux, amd64 and aarch64 wheels\nfor macOS, and amd64, i686, and aarch64 wheels for Windows.\n\norjson does not and will not support PyPy, embedded Python builds for\nAndroid/iOS, or PEP 554 subinterpreters.\n\norjson may support PEP 703 free-threading when it is stable.\n\nReleases follow semantic versioning and serializing a new object type\nwithout an opt-in flag is considered a breaking change.\n\norjson is licensed under both the Apache 2.0 and MIT licenses. The\nrepository and issue tracker is\n[github.com/ijl/orjson](https://github.com/ijl/orjson), and patches may be\nsubmitted there. There is a\n[CHANGELOG](https://github.com/ijl/orjson/blob/master/CHANGELOG.md)\navailable in the repository.\n\n1. [Usage](https://github.com/ijl/orjson?tab=readme-ov-file#usage)\n    1. [Install](https://github.com/ijl/orjson?tab=readme-ov-file#install)\n    2. [Quickstart](https://github.com/ijl/orjson?tab=readme-ov-file#quickstart)\n    3. [Migrating](https://github.com/ijl/orjson?tab=readme-ov-file#migrating)\n    4. [Serialize](https://github.com/ijl/orjson?tab=readme-ov-file#serialize)\n        1. [default](https://github.com/ijl/orjson?tab=readme-ov-file#default)\n        2. [option](https://github.com/ijl/orjson?tab=readme-ov-file#option)\n        3. [Fragment](https://github.com/ijl/orjson?tab=readme-ov-file#fragment)\n    5. [Deserialize](https://github.com/ijl/orjson?tab=readme-ov-file#deserialize)\n2. [Types](https://github.com/ijl/orjson?tab=readme-ov-file#types)\n    1. [dataclass](https://github.com/ijl/orjson?tab=readme-ov-file#dataclass)\n    2. [datetime](https://github.com/ijl/orjson?tab=readme-ov-file#datetime)\n    3. [enum](https://github.com/ijl/orjson?tab=readme-ov-file#enum)\n    4. [float](https://github.com/ijl/orjson?tab=readme-ov-file#float)\n    5. [int](https://github.com/ijl/orjson?tab=readme-ov-file#int)\n    6. [numpy](https://github.com/ijl/orjson?tab=readme-ov-file#numpy)\n    7. [str](https://github.com/ijl/orjson?tab=readme-ov-file#str)\n    8. [uuid](https://github.com/ijl/orjson?tab=readme-ov-file#uuid)\n3. [Testing](https://github.com/ijl/orjson?tab=readme-ov-file#testing)\n4. [Performance](https://github.com/ijl/orjson?tab=readme-ov-file#performance)\n    1. [Latency](https://github.com/ijl/orjson?tab=readme-ov-file#latency)\n    2. [Reproducing](https://github.com/ijl/orjson?tab=readme-ov-file#reproducing)\n5. [Questions](https://github.com/ijl/orjson?tab=readme-ov-file#questions)\n6. [Packaging](https://github.com/ijl/orjson?tab=readme-ov-file#packaging)\n7. [License](https://github.com/ijl/orjson?tab=readme-ov-file#license)\n\n## Usage\n\n### Install\n\nTo install a wheel from PyPI, install the `orjson` package.\n\nIn `requirements.in` or `requirements.txt` format, specify:\n\n```txt\norjson \u003e= 3.10,\u003c4\n```\n\nIn `pyproject.toml` format, specify:\n\n```toml\norjson = \"^3.10\"\n```\n\nTo build a wheel, see [packaging](https://github.com/ijl/orjson?tab=readme-ov-file#packaging).\n\n### Quickstart\n\nThis is an example of serializing, with options specified, and deserializing:\n\n```python\n\u003e\u003e\u003e import orjson, datetime, numpy\n\u003e\u003e\u003e data = {\n    \"type\": \"job\",\n    \"created_at\": datetime.datetime(1970, 1, 1),\n    \"status\": \"🆗\",\n    \"payload\": numpy.array([[1, 2], [3, 4]]),\n}\n\u003e\u003e\u003e orjson.dumps(data, option=orjson.OPT_NAIVE_UTC | orjson.OPT_SERIALIZE_NUMPY)\nb'{\"type\":\"job\",\"created_at\":\"1970-01-01T00:00:00+00:00\",\"status\":\"\\xf0\\x9f\\x86\\x97\",\"payload\":[[1,2],[3,4]]}'\n\u003e\u003e\u003e orjson.loads(_)\n{'type': 'job', 'created_at': '1970-01-01T00:00:00+00:00', 'status': '🆗', 'payload': [[1, 2], [3, 4]]}\n```\n\n### Migrating\n\norjson version 3 serializes more types than version 2. Subclasses of `str`,\n`int`, `dict`, and `list` are now serialized. This is faster and more similar\nto the standard library. It can be disabled with\n`orjson.OPT_PASSTHROUGH_SUBCLASS`.`dataclasses.dataclass` instances\nare now serialized by default and cannot be customized in a\n`default` function unless `option=orjson.OPT_PASSTHROUGH_DATACLASS` is\nspecified. `uuid.UUID` instances are serialized by default.\nFor any type that is now serialized,\nimplementations in a `default` function and options enabling them can be\nremoved but do not need to be. There was no change in deserialization.\n\nTo migrate from the standard library, the largest difference is that\n`orjson.dumps` returns `bytes` and `json.dumps` returns a `str`.\n\nUsers with `dict` objects using non-`str` keys should specify `option=orjson.OPT_NON_STR_KEYS`.\n\n`sort_keys` is replaced by `option=orjson.OPT_SORT_KEYS`.\n\n`indent` is replaced by `option=orjson.OPT_INDENT_2` and other levels of indentation are not\nsupported.\n\n`ensure_ascii` is probably not relevant today and UTF-8 characters cannot be\nescaped to ASCII.\n\n### Serialize\n\n```python\ndef dumps(\n    __obj: Any,\n    default: Optional[Callable[[Any], Any]] = ...,\n    option: Optional[int] = ...,\n) -\u003e bytes: ...\n```\n\n`dumps()` serializes Python objects to JSON.\n\nIt natively serializes\n`str`, `dict`, `list`, `tuple`, `int`, `float`, `bool`, `None`,\n`dataclasses.dataclass`, `typing.TypedDict`, `datetime.datetime`,\n`datetime.date`, `datetime.time`, `uuid.UUID`, `numpy.ndarray`, and\n`orjson.Fragment` instances. It supports arbitrary types through `default`. It\nserializes subclasses of `str`, `int`, `dict`, `list`,\n`dataclasses.dataclass`, and `enum.Enum`. It does not serialize subclasses\nof `tuple` to avoid serializing `namedtuple` objects as arrays. To avoid\nserializing subclasses, specify the option `orjson.OPT_PASSTHROUGH_SUBCLASS`.\n\nThe output is a `bytes` object containing UTF-8.\n\nThe global interpreter lock (GIL) is held for the duration of the call.\n\nIt raises `JSONEncodeError` on an unsupported type. This exception message\ndescribes the invalid object with the error message\n`Type is not JSON serializable: ...`. To fix this, specify\n[default](https://github.com/ijl/orjson?tab=readme-ov-file#default).\n\nIt raises `JSONEncodeError` on a `str` that contains invalid UTF-8.\n\nIt raises `JSONEncodeError` on an integer that exceeds 64 bits by default or,\nwith `OPT_STRICT_INTEGER`, 53 bits.\n\nIt raises `JSONEncodeError` if a `dict` has a key of a type other than `str`,\nunless `OPT_NON_STR_KEYS` is specified.\n\nIt raises `JSONEncodeError` if the output of `default` recurses to handling by\n`default` more than 254 levels deep.\n\nIt raises `JSONEncodeError` on circular references.\n\nIt raises `JSONEncodeError`  if a `tzinfo` on a datetime object is\nunsupported.\n\n`JSONEncodeError` is a subclass of `TypeError`. This is for compatibility\nwith the standard library.\n\nIf the failure was caused by an exception in `default` then\n`JSONEncodeError` chains the original exception as `__cause__`.\n\n#### default\n\nTo serialize a subclass or arbitrary types, specify `default` as a\ncallable that returns a supported type. `default` may be a function,\nlambda, or callable class instance. To specify that a type was not\nhandled by `default`, raise an exception such as `TypeError`.\n\n```python\n\u003e\u003e\u003e import orjson, decimal\n\u003e\u003e\u003e\ndef default(obj):\n    if isinstance(obj, decimal.Decimal):\n        return str(obj)\n    raise TypeError\n\n\u003e\u003e\u003e orjson.dumps(decimal.Decimal(\"0.0842389659712649442845\"))\nJSONEncodeError: Type is not JSON serializable: decimal.Decimal\n\u003e\u003e\u003e orjson.dumps(decimal.Decimal(\"0.0842389659712649442845\"), default=default)\nb'\"0.0842389659712649442845\"'\n\u003e\u003e\u003e orjson.dumps({1, 2}, default=default)\norjson.JSONEncodeError: Type is not JSON serializable: set\n```\n\nThe `default` callable may return an object that itself\nmust be handled by `default` up to 254 times before an exception\nis raised.\n\nIt is important that `default` raise an exception if a type cannot be handled.\nPython otherwise implicitly returns `None`, which appears to the caller\nlike a legitimate value and is serialized:\n\n```python\n\u003e\u003e\u003e import orjson, json\n\u003e\u003e\u003e\ndef default(obj):\n    if isinstance(obj, decimal.Decimal):\n        return str(obj)\n\n\u003e\u003e\u003e orjson.dumps({\"set\":{1, 2}}, default=default)\nb'{\"set\":null}'\n\u003e\u003e\u003e json.dumps({\"set\":{1, 2}}, default=default)\n'{\"set\":null}'\n```\n\n#### option\n\nTo modify how data is serialized, specify `option`. Each `option` is an integer\nconstant in `orjson`. To specify multiple options, mask them together, e.g.,\n`option=orjson.OPT_STRICT_INTEGER | orjson.OPT_NAIVE_UTC`.\n\n##### OPT_APPEND_NEWLINE\n\nAppend `\\n` to the output. This is a convenience and optimization for the\npattern of `dumps(...) + \"\\n\"`. `bytes` objects are immutable and this\npattern copies the original contents.\n\n```python\n\u003e\u003e\u003e import orjson\n\u003e\u003e\u003e orjson.dumps([])\nb\"[]\"\n\u003e\u003e\u003e orjson.dumps([], option=orjson.OPT_APPEND_NEWLINE)\nb\"[]\\n\"\n```\n\n##### OPT_INDENT_2\n\nPretty-print output with an indent of two spaces. This is equivalent to\n`indent=2` in the standard library. Pretty printing is slower and the output\nlarger. orjson is the fastest compared library at pretty printing and has\nmuch less of a slowdown to pretty print than the standard library does. This\noption is compatible with all other options.\n\n```python\n\u003e\u003e\u003e import orjson\n\u003e\u003e\u003e orjson.dumps({\"a\": \"b\", \"c\": {\"d\": True}, \"e\": [1, 2]})\nb'{\"a\":\"b\",\"c\":{\"d\":true},\"e\":[1,2]}'\n\u003e\u003e\u003e orjson.dumps(\n    {\"a\": \"b\", \"c\": {\"d\": True}, \"e\": [1, 2]},\n    option=orjson.OPT_INDENT_2\n)\nb'{\\n  \"a\": \"b\",\\n  \"c\": {\\n    \"d\": true\\n  },\\n  \"e\": [\\n    1,\\n    2\\n  ]\\n}'\n```\n\nIf displayed, the indentation and linebreaks appear like this:\n\n```json\n{\n  \"a\": \"b\",\n  \"c\": {\n    \"d\": true\n  },\n  \"e\": [\n    1,\n    2\n  ]\n}\n```\n\nThis measures serializing the github.json fixture as compact (52KiB) or\npretty (64KiB):\n\n| Library   |   compact (ms) |   pretty (ms) |   vs. orjson |\n|-----------|----------------|---------------|--------------|\n| orjson    |           0.01 |          0.02 |            1 |\n| json      |           0.13 |          0.54 |           34 |\n\nThis measures serializing the citm_catalog.json fixture, more of a worst\ncase due to the amount of nesting and newlines, as compact (489KiB) or\npretty (1.1MiB):\n\n| Library   |   compact (ms) |   pretty (ms) |   vs. orjson |\n|-----------|----------------|---------------|--------------|\n| orjson    |           0.25 |          0.45 |          1   |\n| json      |           3.01 |         24.42 |         54.4 |\n\nThis can be reproduced using the `pyindent` script.\n\n##### OPT_NAIVE_UTC\n\nSerialize `datetime.datetime` objects without a `tzinfo` as UTC. This\nhas no effect on `datetime.datetime` objects that have `tzinfo` set.\n\n```python\n\u003e\u003e\u003e import orjson, datetime\n\u003e\u003e\u003e orjson.dumps(\n        datetime.datetime(1970, 1, 1, 0, 0, 0),\n    )\nb'\"1970-01-01T00:00:00\"'\n\u003e\u003e\u003e orjson.dumps(\n        datetime.datetime(1970, 1, 1, 0, 0, 0),\n        option=orjson.OPT_NAIVE_UTC,\n    )\nb'\"1970-01-01T00:00:00+00:00\"'\n```\n\n##### OPT_NON_STR_KEYS\n\nSerialize `dict` keys of type other than `str`. This allows `dict` keys\nto be one of `str`, `int`, `float`, `bool`, `None`, `datetime.datetime`,\n`datetime.date`, `datetime.time`, `enum.Enum`, and `uuid.UUID`. For comparison,\nthe standard library serializes `str`, `int`, `float`, `bool` or `None` by\ndefault. orjson benchmarks as being faster at serializing non-`str` keys\nthan other libraries. This option is slower for `str` keys than the default.\n\n```python\n\u003e\u003e\u003e import orjson, datetime, uuid\n\u003e\u003e\u003e orjson.dumps(\n        {uuid.UUID(\"7202d115-7ff3-4c81-a7c1-2a1f067b1ece\"): [1, 2, 3]},\n        option=orjson.OPT_NON_STR_KEYS,\n    )\nb'{\"7202d115-7ff3-4c81-a7c1-2a1f067b1ece\":[1,2,3]}'\n\u003e\u003e\u003e orjson.dumps(\n        {datetime.datetime(1970, 1, 1, 0, 0, 0): [1, 2, 3]},\n        option=orjson.OPT_NON_STR_KEYS | orjson.OPT_NAIVE_UTC,\n    )\nb'{\"1970-01-01T00:00:00+00:00\":[1,2,3]}'\n```\n\nThese types are generally serialized how they would be as\nvalues, e.g., `datetime.datetime` is still an RFC 3339 string and respects\noptions affecting it. The exception is that `int` serialization does not\nrespect `OPT_STRICT_INTEGER`.\n\nThis option has the risk of creating duplicate keys. This is because non-`str`\nobjects may serialize to the same `str` as an existing key, e.g.,\n`{\"1\": true, 1: false}`. The last key to be inserted to the `dict` will be\nserialized last and a JSON deserializer will presumably take the last\noccurrence of a key (in the above, `false`). The first value will be lost.\n\nThis option is compatible with `orjson.OPT_SORT_KEYS`. If sorting is used,\nnote the sort is unstable and will be unpredictable for duplicate keys.\n\n```python\n\u003e\u003e\u003e import orjson, datetime\n\u003e\u003e\u003e orjson.dumps(\n    {\"other\": 1, datetime.date(1970, 1, 5): 2, datetime.date(1970, 1, 3): 3},\n    option=orjson.OPT_NON_STR_KEYS | orjson.OPT_SORT_KEYS\n)\nb'{\"1970-01-03\":3,\"1970-01-05\":2,\"other\":1}'\n```\n\nThis measures serializing 589KiB of JSON comprising a `list` of 100 `dict`\nin which each `dict` has both 365 randomly-sorted `int` keys representing epoch\ntimestamps as well as one `str` key and the value for each key is a\nsingle integer. In \"str keys\", the keys were converted to `str` before\nserialization, and orjson still specifes `option=orjson.OPT_NON_STR_KEYS`\n(which is always somewhat slower).\n\n| Library   |   str keys (ms) |   int keys (ms) | int keys sorted (ms)   |\n|-----------|-----------------|-----------------|------------------------|\n| orjson    |            0.5  |            0.93 | 2.08                   |\n| json      |            2.72 |            3.59 |                        |\n\njson is blank because it\nraises `TypeError` on attempting to sort before converting all keys to `str`.\nThis can be reproduced using the `pynonstr` script.\n\n##### OPT_OMIT_MICROSECONDS\n\nDo not serialize the `microsecond` field on `datetime.datetime` and\n`datetime.time` instances.\n\n```python\n\u003e\u003e\u003e import orjson, datetime\n\u003e\u003e\u003e orjson.dumps(\n        datetime.datetime(1970, 1, 1, 0, 0, 0, 1),\n    )\nb'\"1970-01-01T00:00:00.000001\"'\n\u003e\u003e\u003e orjson.dumps(\n        datetime.datetime(1970, 1, 1, 0, 0, 0, 1),\n        option=orjson.OPT_OMIT_MICROSECONDS,\n    )\nb'\"1970-01-01T00:00:00\"'\n```\n\n##### OPT_PASSTHROUGH_DATACLASS\n\nPassthrough `dataclasses.dataclass` instances to `default`. This allows\ncustomizing their output but is much slower.\n\n\n```python\n\u003e\u003e\u003e import orjson, dataclasses\n\u003e\u003e\u003e\n@dataclasses.dataclass\nclass User:\n    id: str\n    name: str\n    password: str\n\ndef default(obj):\n    if isinstance(obj, User):\n        return {\"id\": obj.id, \"name\": obj.name}\n    raise TypeError\n\n\u003e\u003e\u003e orjson.dumps(User(\"3b1\", \"asd\", \"zxc\"))\nb'{\"id\":\"3b1\",\"name\":\"asd\",\"password\":\"zxc\"}'\n\u003e\u003e\u003e orjson.dumps(User(\"3b1\", \"asd\", \"zxc\"), option=orjson.OPT_PASSTHROUGH_DATACLASS)\nTypeError: Type is not JSON serializable: User\n\u003e\u003e\u003e orjson.dumps(\n        User(\"3b1\", \"asd\", \"zxc\"),\n        option=orjson.OPT_PASSTHROUGH_DATACLASS,\n        default=default,\n    )\nb'{\"id\":\"3b1\",\"name\":\"asd\"}'\n```\n\n##### OPT_PASSTHROUGH_DATETIME\n\nPassthrough `datetime.datetime`, `datetime.date`, and `datetime.time` instances\nto `default`. This allows serializing datetimes to a custom format, e.g.,\nHTTP dates:\n\n```python\n\u003e\u003e\u003e import orjson, datetime\n\u003e\u003e\u003e\ndef default(obj):\n    if isinstance(obj, datetime.datetime):\n        return obj.strftime(\"%a, %d %b %Y %H:%M:%S GMT\")\n    raise TypeError\n\n\u003e\u003e\u003e orjson.dumps({\"created_at\": datetime.datetime(1970, 1, 1)})\nb'{\"created_at\":\"1970-01-01T00:00:00\"}'\n\u003e\u003e\u003e orjson.dumps({\"created_at\": datetime.datetime(1970, 1, 1)}, option=orjson.OPT_PASSTHROUGH_DATETIME)\nTypeError: Type is not JSON serializable: datetime.datetime\n\u003e\u003e\u003e orjson.dumps(\n        {\"created_at\": datetime.datetime(1970, 1, 1)},\n        option=orjson.OPT_PASSTHROUGH_DATETIME,\n        default=default,\n    )\nb'{\"created_at\":\"Thu, 01 Jan 1970 00:00:00 GMT\"}'\n```\n\nThis does not affect datetimes in `dict` keys if using OPT_NON_STR_KEYS.\n\n##### OPT_PASSTHROUGH_SUBCLASS\n\nPassthrough subclasses of builtin types to `default`.\n\n```python\n\u003e\u003e\u003e import orjson\n\u003e\u003e\u003e\nclass Secret(str):\n    pass\n\ndef default(obj):\n    if isinstance(obj, Secret):\n        return \"******\"\n    raise TypeError\n\n\u003e\u003e\u003e orjson.dumps(Secret(\"zxc\"))\nb'\"zxc\"'\n\u003e\u003e\u003e orjson.dumps(Secret(\"zxc\"), option=orjson.OPT_PASSTHROUGH_SUBCLASS)\nTypeError: Type is not JSON serializable: Secret\n\u003e\u003e\u003e orjson.dumps(Secret(\"zxc\"), option=orjson.OPT_PASSTHROUGH_SUBCLASS, default=default)\nb'\"******\"'\n```\n\nThis does not affect serializing subclasses as `dict` keys if using\nOPT_NON_STR_KEYS.\n\n##### OPT_SERIALIZE_DATACLASS\n\nThis is deprecated and has no effect in version 3. In version 2 this was\nrequired to serialize  `dataclasses.dataclass` instances. For more, see\n[dataclass](https://github.com/ijl/orjson?tab=readme-ov-file#dataclass).\n\n##### OPT_SERIALIZE_NUMPY\n\nSerialize `numpy.ndarray` instances. For more, see\n[numpy](https://github.com/ijl/orjson?tab=readme-ov-file#numpy).\n\n##### OPT_SERIALIZE_UUID\n\nThis is deprecated and has no effect in version 3. In version 2 this was\nrequired to serialize `uuid.UUID` instances. For more, see\n[UUID](https://github.com/ijl/orjson?tab=readme-ov-file#UUID).\n\n##### OPT_SORT_KEYS\n\nSerialize `dict` keys in sorted order. The default is to serialize in an\nunspecified order. This is equivalent to `sort_keys=True` in the standard\nlibrary.\n\nThis can be used to ensure the order is deterministic for hashing or tests.\nIt has a substantial performance penalty and is not recommended in general.\n\n```python\n\u003e\u003e\u003e import orjson\n\u003e\u003e\u003e orjson.dumps({\"b\": 1, \"c\": 2, \"a\": 3})\nb'{\"b\":1,\"c\":2,\"a\":3}'\n\u003e\u003e\u003e orjson.dumps({\"b\": 1, \"c\": 2, \"a\": 3}, option=orjson.OPT_SORT_KEYS)\nb'{\"a\":3,\"b\":1,\"c\":2}'\n```\n\nThis measures serializing the twitter.json fixture unsorted and sorted:\n\n| Library   |   unsorted (ms) |   sorted (ms) |   vs. orjson |\n|-----------|-----------------|---------------|--------------|\n| orjson    |            0.11 |          0.3  |          1   |\n| json      |            1.36 |          1.93 |          6.4 |\n\nThe benchmark can be reproduced using the `pysort` script.\n\nThe sorting is not collation/locale-aware:\n\n```python\n\u003e\u003e\u003e import orjson\n\u003e\u003e\u003e orjson.dumps({\"a\": 1, \"ä\": 2, \"A\": 3}, option=orjson.OPT_SORT_KEYS)\nb'{\"A\":3,\"a\":1,\"\\xc3\\xa4\":2}'\n```\n\nThis is the same sorting behavior as the standard library.\n\n`dataclass` also serialize as maps but this has no effect on them.\n\n##### OPT_STRICT_INTEGER\n\nEnforce 53-bit limit on integers. The limit is otherwise 64 bits, the same as\nthe Python standard library. For more, see [int](https://github.com/ijl/orjson?tab=readme-ov-file#int).\n\n##### OPT_UTC_Z\n\nSerialize a UTC timezone on `datetime.datetime` instances as `Z` instead\nof `+00:00`.\n\n```python\n\u003e\u003e\u003e import orjson, datetime, zoneinfo\n\u003e\u003e\u003e orjson.dumps(\n        datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=zoneinfo.ZoneInfo(\"UTC\")),\n    )\nb'\"1970-01-01T00:00:00+00:00\"'\n\u003e\u003e\u003e orjson.dumps(\n        datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=zoneinfo.ZoneInfo(\"UTC\")),\n        option=orjson.OPT_UTC_Z\n    )\nb'\"1970-01-01T00:00:00Z\"'\n```\n\n#### Fragment\n\n`orjson.Fragment` includes already-serialized JSON in a document. This is an\nefficient way to include JSON blobs from a cache, JSONB field, or separately\nserialized object without first deserializing to Python objects via `loads()`.\n\n```python\n\u003e\u003e\u003e import orjson\n\u003e\u003e\u003e orjson.dumps({\"key\": \"zxc\", \"data\": orjson.Fragment(b'{\"a\": \"b\", \"c\": 1}')})\nb'{\"key\":\"zxc\",\"data\":{\"a\": \"b\", \"c\": 1}}'\n```\n\nIt does no reformatting: `orjson.OPT_INDENT_2` will not affect a\ncompact blob nor will a pretty-printed JSON blob be rewritten as compact.\n\nThe input must be `bytes` or `str` and given as a positional argument.\n\nThis raises `orjson.JSONEncodeError` if a `str` is given and the input is\nnot valid UTF-8. It otherwise does no validation and it is possible to\nwrite invalid JSON. This does not escape characters. The implementation is\ntested to not crash if given invalid strings or invalid JSON.\n\n### Deserialize\n\n```python\ndef loads(__obj: Union[bytes, bytearray, memoryview, str]) -\u003e Any: ...\n```\n\n`loads()` deserializes JSON to Python objects. It deserializes to `dict`,\n`list`, `int`, `float`, `str`, `bool`, and `None` objects.\n\n`bytes`, `bytearray`, `memoryview`, and `str` input are accepted. If the input\nexists as a `memoryview`, `bytearray`, or `bytes` object, it is recommended to\npass these directly rather than creating an unnecessary `str` object. That is,\n`orjson.loads(b\"{}\")` instead of `orjson.loads(b\"{}\".decode(\"utf-8\"))`. This\nhas lower memory usage and lower latency.\n\nThe input must be valid UTF-8.\n\norjson maintains a cache of map keys for the duration of the process. This\ncauses a net reduction in memory usage by avoiding duplicate strings. The\nkeys must be at most 64 bytes to be cached and 2048 entries are stored.\n\nThe global interpreter lock (GIL) is held for the duration of the call.\n\nIt raises `JSONDecodeError` if given an invalid type or invalid\nJSON. This includes if the input contains `NaN`, `Infinity`, or `-Infinity`,\nwhich the standard library allows, but is not valid JSON.\n\nIt raises `JSONDecodeError` if a combination of array or object recurses\n1024 levels deep.\n\n`JSONDecodeError` is a subclass of `json.JSONDecodeError` and `ValueError`.\nThis is for compatibility with the standard library.\n\n## Types\n\n### dataclass\n\norjson serializes instances of `dataclasses.dataclass` natively. It serializes\ninstances 40-50x as fast as other libraries and avoids a severe slowdown seen\nin other libraries compared to serializing `dict`.\n\nIt is supported to pass all variants of dataclasses, including dataclasses\nusing `__slots__`, frozen dataclasses, those with optional or default\nattributes, and subclasses. There is a performance benefit to not\nusing `__slots__`.\n\n| Library   |   dict (ms) |   dataclass (ms) |   vs. orjson |\n|-----------|-------------|------------------|--------------|\n| orjson    |        0.43 |             0.95 |            1 |\n| json      |        5.81 |            38.32 |           40 |\n\nThis measures serializing 555KiB of JSON, orjson natively and other libraries\nusing `default` to serialize the output of `dataclasses.asdict()`. This can be\nreproduced using the `pydataclass` script.\n\nDataclasses are serialized as maps, with every attribute serialized and in\nthe order given on class definition:\n\n```python\n\u003e\u003e\u003e import dataclasses, orjson, typing\n\n@dataclasses.dataclass\nclass Member:\n    id: int\n    active: bool = dataclasses.field(default=False)\n\n@dataclasses.dataclass\nclass Object:\n    id: int\n    name: str\n    members: typing.List[Member]\n\n\u003e\u003e\u003e orjson.dumps(Object(1, \"a\", [Member(1, True), Member(2)]))\nb'{\"id\":1,\"name\":\"a\",\"members\":[{\"id\":1,\"active\":true},{\"id\":2,\"active\":false}]}'\n```\n\n### datetime\n\norjson serializes `datetime.datetime` objects to\n[RFC 3339](https://tools.ietf.org/html/rfc3339) format,\ne.g., \"1970-01-01T00:00:00+00:00\". This is a subset of ISO 8601 and is\ncompatible with `isoformat()` in the standard library.\n\n```python\n\u003e\u003e\u003e import orjson, datetime, zoneinfo\n\u003e\u003e\u003e orjson.dumps(\n    datetime.datetime(2018, 12, 1, 2, 3, 4, 9, tzinfo=zoneinfo.ZoneInfo(\"Australia/Adelaide\"))\n)\nb'\"2018-12-01T02:03:04.000009+10:30\"'\n\u003e\u003e\u003e orjson.dumps(\n    datetime.datetime(2100, 9, 1, 21, 55, 2).replace(tzinfo=zoneinfo.ZoneInfo(\"UTC\"))\n)\nb'\"2100-09-01T21:55:02+00:00\"'\n\u003e\u003e\u003e orjson.dumps(\n    datetime.datetime(2100, 9, 1, 21, 55, 2)\n)\nb'\"2100-09-01T21:55:02\"'\n```\n\n`datetime.datetime` supports instances with a `tzinfo` that is `None`,\n`datetime.timezone.utc`, a timezone instance from the python3.9+ `zoneinfo`\nmodule, or a timezone instance from the third-party `pendulum`, `pytz`, or\n`dateutil`/`arrow` libraries.\n\nIt is fastest to use the standard library's `zoneinfo.ZoneInfo` for timezones.\n\n`datetime.time` objects must not have a `tzinfo`.\n\n```python\n\u003e\u003e\u003e import orjson, datetime\n\u003e\u003e\u003e orjson.dumps(datetime.time(12, 0, 15, 290))\nb'\"12:00:15.000290\"'\n```\n\n`datetime.date` objects will always serialize.\n\n```python\n\u003e\u003e\u003e import orjson, datetime\n\u003e\u003e\u003e orjson.dumps(datetime.date(1900, 1, 2))\nb'\"1900-01-02\"'\n```\n\nErrors with `tzinfo` result in `JSONEncodeError` being raised.\n\nTo disable serialization of `datetime` objects specify the option\n`orjson.OPT_PASSTHROUGH_DATETIME`.\n\nTo use \"Z\" suffix instead of \"+00:00\" to indicate UTC (\"Zulu\") time, use the option\n`orjson.OPT_UTC_Z`.\n\nTo assume datetimes without timezone are UTC, use the option `orjson.OPT_NAIVE_UTC`.\n\n### enum\n\norjson serializes enums natively. Options apply to their values.\n\n```python\n\u003e\u003e\u003e import enum, datetime, orjson\n\u003e\u003e\u003e\nclass DatetimeEnum(enum.Enum):\n    EPOCH = datetime.datetime(1970, 1, 1, 0, 0, 0)\n\u003e\u003e\u003e orjson.dumps(DatetimeEnum.EPOCH)\nb'\"1970-01-01T00:00:00\"'\n\u003e\u003e\u003e orjson.dumps(DatetimeEnum.EPOCH, option=orjson.OPT_NAIVE_UTC)\nb'\"1970-01-01T00:00:00+00:00\"'\n```\n\nEnums with members that are not supported types can be serialized using\n`default`:\n\n```python\n\u003e\u003e\u003e import enum, orjson\n\u003e\u003e\u003e\nclass Custom:\n    def __init__(self, val):\n        self.val = val\n\ndef default(obj):\n    if isinstance(obj, Custom):\n        return obj.val\n    raise TypeError\n\nclass CustomEnum(enum.Enum):\n    ONE = Custom(1)\n\n\u003e\u003e\u003e orjson.dumps(CustomEnum.ONE, default=default)\nb'1'\n```\n\n### float\n\norjson serializes and deserializes double precision floats with no loss of\nprecision and consistent rounding.\n\n`orjson.dumps()` serializes Nan, Infinity, and -Infinity, which are not\ncompliant JSON, as `null`:\n\n```python\n\u003e\u003e\u003e import orjson, json\n\u003e\u003e\u003e orjson.dumps([float(\"NaN\"), float(\"Infinity\"), float(\"-Infinity\")])\nb'[null,null,null]'\n\u003e\u003e\u003e json.dumps([float(\"NaN\"), float(\"Infinity\"), float(\"-Infinity\")])\n'[NaN, Infinity, -Infinity]'\n```\n\n### int\n\norjson serializes and deserializes 64-bit integers by default. The range\nsupported is a signed 64-bit integer's minimum (-9223372036854775807) to\nan unsigned 64-bit integer's maximum (18446744073709551615). This\nis widely compatible, but there are implementations\nthat only support 53-bits for integers, e.g.,\nweb browsers. For those implementations, `dumps()` can be configured to\nraise a `JSONEncodeError` on values exceeding the 53-bit range.\n\n```python\n\u003e\u003e\u003e import orjson\n\u003e\u003e\u003e orjson.dumps(9007199254740992)\nb'9007199254740992'\n\u003e\u003e\u003e orjson.dumps(9007199254740992, option=orjson.OPT_STRICT_INTEGER)\nJSONEncodeError: Integer exceeds 53-bit range\n\u003e\u003e\u003e orjson.dumps(-9007199254740992, option=orjson.OPT_STRICT_INTEGER)\nJSONEncodeError: Integer exceeds 53-bit range\n```\n\n### numpy\n\norjson natively serializes `numpy.ndarray` and individual\n`numpy.float64`, `numpy.float32`, `numpy.float16` (`numpy.half`),\n`numpy.int64`, `numpy.int32`, `numpy.int16`, `numpy.int8`,\n`numpy.uint64`, `numpy.uint32`, `numpy.uint16`, `numpy.uint8`,\n`numpy.uintp`, `numpy.intp`, `numpy.datetime64`, and `numpy.bool`\ninstances.\n\norjson is compatible with both numpy v1 and v2.\n\norjson is faster than all compared libraries at serializing\nnumpy instances. Serializing numpy data requires specifying\n`option=orjson.OPT_SERIALIZE_NUMPY`.\n\n```python\n\u003e\u003e\u003e import orjson, numpy\n\u003e\u003e\u003e orjson.dumps(\n        numpy.array([[1, 2, 3], [4, 5, 6]]),\n        option=orjson.OPT_SERIALIZE_NUMPY,\n)\nb'[[1,2,3],[4,5,6]]'\n```\n\nThe array must be a contiguous C array (`C_CONTIGUOUS`) and one of the\nsupported datatypes.\n\nNote a difference between serializing `numpy.float32` using `ndarray.tolist()`\nor `orjson.dumps(..., option=orjson.OPT_SERIALIZE_NUMPY)`: `tolist()` converts\nto a `double` before serializing and orjson's native path does not. This\ncan result in different rounding.\n\n`numpy.datetime64` instances are serialized as RFC 3339 strings and\ndatetime options affect them.\n\n```python\n\u003e\u003e\u003e import orjson, numpy\n\u003e\u003e\u003e orjson.dumps(\n        numpy.datetime64(\"2021-01-01T00:00:00.172\"),\n        option=orjson.OPT_SERIALIZE_NUMPY,\n)\nb'\"2021-01-01T00:00:00.172000\"'\n\u003e\u003e\u003e orjson.dumps(\n        numpy.datetime64(\"2021-01-01T00:00:00.172\"),\n        option=(\n            orjson.OPT_SERIALIZE_NUMPY |\n            orjson.OPT_NAIVE_UTC |\n            orjson.OPT_OMIT_MICROSECONDS\n        ),\n)\nb'\"2021-01-01T00:00:00+00:00\"'\n```\n\nIf an array is not a contiguous C array, contains an unsupported datatype,\nor contains a `numpy.datetime64` using an unsupported representation\n(e.g., picoseconds), orjson falls through to `default`. In `default`,\n`obj.tolist()` can be specified.\n\nIf an array is not in the native endianness, e.g., an array of big-endian values\non a little-endian system, `orjson.JSONEncodeError`  is raised.\n\nIf an array is malformed, `orjson.JSONEncodeError` is raised.\n\nThis measures serializing 92MiB of JSON from an `numpy.ndarray` with\ndimensions of `(50000, 100)` and `numpy.float64` values:\n\n| Library   | Latency (ms)   |   RSS diff (MiB) |   vs. orjson |\n|-----------|----------------|------------------|--------------|\n| orjson    | 105            |              105 |          1   |\n| json      | 1,481          |              295 |         14.2 |\n\nThis measures serializing 100MiB of JSON from an `numpy.ndarray` with\ndimensions of `(100000, 100)` and `numpy.int32` values:\n\n| Library   |   Latency (ms) |   RSS diff (MiB) |   vs. orjson |\n|-----------|----------------|------------------|--------------|\n| orjson    |             68 |              119 |          1   |\n| json      |            684 |              501 |         10.1 |\n\nThis measures serializing 105MiB of JSON from an `numpy.ndarray` with\ndimensions of `(100000, 200)` and `numpy.bool` values:\n\n| Library   |   Latency (ms) |   RSS diff (MiB) |   vs. orjson |\n|-----------|----------------|------------------|--------------|\n| orjson    |             50 |              125 |          1   |\n| json      |            573 |              398 |         11.5 |\n\nIn these benchmarks, orjson serializes natively and `json` serializes\n`ndarray.tolist()` via `default`. The RSS column measures peak memory\nusage during serialization. This can be reproduced using the `pynumpy` script.\n\norjson does not have an installation or compilation dependency on numpy. The\nimplementation is independent, reading `numpy.ndarray` using\n`PyArrayInterface`.\n\n### str\n\norjson is strict about UTF-8 conformance. This is stricter than the standard\nlibrary's json module, which will serialize and deserialize UTF-16 surrogates,\ne.g., \"\\ud800\", that are invalid UTF-8.\n\nIf `orjson.dumps()` is given a `str` that does not contain valid UTF-8,\n`orjson.JSONEncodeError` is raised. If `loads()` receives invalid UTF-8,\n`orjson.JSONDecodeError` is raised.\n\n```python\n\u003e\u003e\u003e import orjson, json\n\u003e\u003e\u003e orjson.dumps('\\ud800')\nJSONEncodeError: str is not valid UTF-8: surrogates not allowed\n\u003e\u003e\u003e json.dumps('\\ud800')\n'\"\\\\ud800\"'\n\u003e\u003e\u003e orjson.loads('\"\\\\ud800\"')\nJSONDecodeError: unexpected end of hex escape at line 1 column 8: line 1 column 1 (char 0)\n\u003e\u003e\u003e json.loads('\"\\\\ud800\"')\n'\\ud800'\n```\n\nTo make a best effort at deserializing bad input, first decode `bytes` using\nthe `replace` or `lossy` argument for `errors`:\n\n```python\n\u003e\u003e\u003e import orjson\n\u003e\u003e\u003e orjson.loads(b'\"\\xed\\xa0\\x80\"')\nJSONDecodeError: str is not valid UTF-8: surrogates not allowed\n\u003e\u003e\u003e orjson.loads(b'\"\\xed\\xa0\\x80\"'.decode(\"utf-8\", \"replace\"))\n'���'\n```\n\n### uuid\n\norjson serializes `uuid.UUID` instances to\n[RFC 4122](https://tools.ietf.org/html/rfc4122) format, e.g.,\n\"f81d4fae-7dec-11d0-a765-00a0c91e6bf6\".\n\n``` python\n\u003e\u003e\u003e import orjson, uuid\n\u003e\u003e\u003e orjson.dumps(uuid.uuid5(uuid.NAMESPACE_DNS, \"python.org\"))\nb'\"886313e1-3b8a-5372-9b90-0c9aee199e5d\"'\n```\n\n## Testing\n\nThe library has comprehensive tests. There are tests against fixtures in the\n[JSONTestSuite](https://github.com/nst/JSONTestSuite) and\n[nativejson-benchmark](https://github.com/miloyip/nativejson-benchmark)\nrepositories. It is tested to not crash against the\n[Big List of Naughty Strings](https://github.com/minimaxir/big-list-of-naughty-strings).\nIt is tested to not leak memory. It is tested to not crash\nagainst and not accept invalid UTF-8. There are integration tests\nexercising the library's use in web servers (gunicorn using multiprocess/forked\nworkers) and when\nmultithreaded. It also uses some tests from the ultrajson library.\n\norjson is the most correct of the compared libraries. This graph shows how each\nlibrary handles a combined 342 JSON fixtures from the\n[JSONTestSuite](https://github.com/nst/JSONTestSuite) and\n[nativejson-benchmark](https://github.com/miloyip/nativejson-benchmark) tests:\n\n| Library    |   Invalid JSON documents not rejected |   Valid JSON documents not deserialized |\n|------------|---------------------------------------|-----------------------------------------|\n| orjson     |                                     0 |                                       0 |\n| json       |                                    17 |                                       0 |\n\nThis shows that all libraries deserialize valid JSON but only orjson\ncorrectly rejects the given invalid JSON fixtures. Errors are largely due to\naccepting invalid strings and numbers.\n\nThe graph above can be reproduced using the `pycorrectness` script.\n\n## Performance\n\nSerialization and deserialization performance of orjson is consistently better\nthan the standard library's `json`. The graphs below illustrate a few commonly\nused documents.\n\n### Latency\n\n![Serialization](doc/serialization.png)\n\n![Deserialization](doc/deserialization.png)\n\n#### twitter.json serialization\n\n| Library   |   Median latency (milliseconds) |   Operations per second |   Relative (latency) |\n|-----------|---------------------------------|-------------------------|----------------------|\n| orjson    |                             0.1 |                    8453 |                  1   |\n| json      |                             1.3 |                     765 |                 11.1 |\n\n#### twitter.json deserialization\n\n| Library   |   Median latency (milliseconds) |   Operations per second |   Relative (latency) |\n|-----------|---------------------------------|-------------------------|----------------------|\n| orjson    |                             0.5 |                    1889 |                  1   |\n| json      |                             2.2 |                     453 |                  4.2 |\n\n#### github.json serialization\n\n| Library   |   Median latency (milliseconds) |   Operations per second |   Relative (latency) |\n|-----------|---------------------------------|-------------------------|----------------------|\n| orjson    |                            0.01 |                  103693 |                  1   |\n| json      |                            0.13 |                    7648 |                 13.6 |\n\n#### github.json deserialization\n\n| Library   |   Median latency (milliseconds) |   Operations per second |   Relative (latency) |\n|-----------|---------------------------------|-------------------------|----------------------|\n| orjson    |                            0.04 |                   23264 |                  1   |\n| json      |                            0.1  |                   10430 |                  2.2 |\n\n#### citm_catalog.json serialization\n\n| Library   |   Median latency (milliseconds) |   Operations per second |   Relative (latency) |\n|-----------|---------------------------------|-------------------------|----------------------|\n| orjson    |                             0.3 |                    3975 |                  1   |\n| json      |                             3   |                     338 |                 11.8 |\n\n#### citm_catalog.json deserialization\n\n| Library   |   Median latency (milliseconds) |   Operations per second |   Relative (latency) |\n|-----------|---------------------------------|-------------------------|----------------------|\n| orjson    |                             1.3 |                     781 |                  1   |\n| json      |                             4   |                     250 |                  3.1 |\n\n#### canada.json serialization\n\n| Library   |   Median latency (milliseconds) |   Operations per second |   Relative (latency) |\n|-----------|---------------------------------|-------------------------|----------------------|\n| orjson    |                             2.5 |                     399 |                  1   |\n| json      |                            29.8 |                      33 |                 11.9 |\n\n#### canada.json deserialization\n\n| Library   |   Median latency (milliseconds) |   Operations per second |   Relative (latency) |\n|-----------|---------------------------------|-------------------------|----------------------|\n| orjson    |                               3 |                     333 |                    1 |\n| json      |                              18 |                      55 |                    6 |\n\n### Reproducing\n\nThe above was measured using Python 3.11.10 in a Fedora 42 container on an\nx86-64-v4 machine using the\n`orjson-3.10.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl`\nartifact on PyPI. The latency results can be reproduced using the `pybench` script.\n\n## Questions\n\n### Why can't I install it from PyPI?\n\nProbably `pip` needs to be upgraded to version 20.3 or later to support\nthe latest manylinux_x_y or universal2 wheel formats.\n\n### \"Cargo, the Rust package manager, is not installed or is not on PATH.\"\n\nThis happens when there are no binary wheels (like manylinux) for your\nplatform on PyPI. You can install [Rust](https://www.rust-lang.org/) through\n`rustup` or a package manager and then it will compile.\n\n### Will it deserialize to dataclasses, UUIDs, decimals, etc or support object_hook?\n\nNo. This requires a schema specifying what types are expected and how to\nhandle errors etc. This is addressed by data validation libraries a\nlevel above this.\n\n### Will it serialize to `str`?\n\nNo. `bytes` is the correct type for a serialized blob.\n\n### Will it support NDJSON or JSONL?\n\nNo. [orjsonl](https://github.com/umarbutler/orjsonl) may be appropriate.\n\n### Will it support JSON5 or RJSON?\n\nNo, it supports RFC 8259.\n\n## Packaging\n\nTo package orjson requires at least [Rust](https://www.rust-lang.org/) 1.82\nand the [maturin](https://github.com/PyO3/maturin) build tool. The recommended\nbuild command is:\n\n```sh\nmaturin build --release --strip\n```\n\nIt benefits from also having a C build environment to compile a faster\ndeserialization backend. See this project's `manylinux_2_28` builds for an\nexample using clang and LTO.\n\nThe project's own CI tests against `nightly-2025-04-15` and stable 1.82. It\nis prudent to pin the nightly version because that channel can introduce\nbreaking changes. There is a significant performance benefit to using\nnightly.\n\norjson is tested for amd64, aarch64, and i686 on Linux and cross-compiles for\narm7, ppc64le, and s390x. It is tested for either aarch64 or amd64 on macOS and\ncross-compiles for the other, depending on version. For Windows it is\ntested on amd64 and i686.\n\nThere are no runtime dependencies other than libc.\n\nThe source distribution on PyPI contains all dependencies' source and can be\nbuilt without network access. The file can be downloaded from\n`https://files.pythonhosted.org/packages/source/o/orjson/orjson-${version}.tar.gz`.\n\norjson's tests are included in the source distribution on PyPI. The tests\nrequire only `pytest`. There are optional packages such as `pytz` and `numpy`\nlisted in `test/requirements.txt` and used in ~10% of tests. Not having these\ndependencies causes the tests needing them to skip. Tests can be run\nwith `pytest -q test`.\n\n## License\n\norjson was written by ijl \u003c\u003cijl@mailbox.org\u003e\u003e, copyright 2018 - 2025, available\nto you under either the Apache 2 license or MIT license at your choice.\n","funding_links":[],"categories":["Data Serialization","Python","Data Format \u0026 I/O","Topics Index","Python 程序","Data Serialization Formats","Data Processing","Serialization"],"sub_categories":["For Python","Commonly Useful Knowledge","网络服务_其他"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fijl%2Forjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fijl%2Forjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fijl%2Forjson/lists"}