{"id":24964739,"url":"https://github.com/gaming32/json-serialize","last_synced_at":"2026-04-25T23:34:58.859Z","repository":{"id":62572947,"uuid":"233136207","full_name":"Gaming32/JSON-Serialize","owner":"Gaming32","description":"Serializes objects to json","archived":false,"fork":false,"pushed_at":"2020-09-24T16:18:45.000Z","size":112,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-04T06:03:06.142Z","etag":null,"topics":["json","library","python","serialization"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Gaming32.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-10T21:51:45.000Z","updated_at":"2020-09-24T16:18:49.000Z","dependencies_parsed_at":"2022-11-03T18:32:07.065Z","dependency_job_id":null,"html_url":"https://github.com/Gaming32/JSON-Serialize","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gaming32%2FJSON-Serialize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gaming32%2FJSON-Serialize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gaming32%2FJSON-Serialize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gaming32%2FJSON-Serialize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gaming32","download_url":"https://codeload.github.com/Gaming32/JSON-Serialize/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246117756,"owners_count":20726069,"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":["json","library","python","serialization"],"created_at":"2025-02-03T10:17:51.282Z","updated_at":"2026-04-25T23:34:58.810Z","avatar_url":"https://github.com/Gaming32.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Using the Module\n## Converting to a Python `dict` object\nTo convert a Python object to a Python `dict` (Dictionary) object, you use the `convert_to_data` function.\n\n### Usage\n`convert_to_data(obj, _reached=None)`\n\n### Arguments\n\nArgument   | Type       | Description | Default Value\n---------- | ---------- | ----------- | -----------\nobj | Any | The object to convert to a Python `dict` object | required\n_reached | Set | A value passed to the function internally for recursive data structures | None\n\n### Example\n\n```python\n\u003e\u003e\u003e class A:\n...     def __init__(self, obj):\n...         self.obj = obj\n... \n\u003e\u003e\u003e obj1 = A('Hello World!')\n\u003e\u003e\u003e data = convert_to_data(obj1)\n\u003e\u003e\u003e data\n{'version': 1, 'min_version': 1, 'module': '__main__', 'type': 'A', 'attrs': {'obj': {'value': 'Hello World!', 'uuid': 192575949315149374534195982055635280394, 'mode': 'fallback'}}, 'uuid': 192575949235921212021180267458779800074}\n```\n\n## Converting back to a normal Python object\nTo convert a Python mapping back into a normal Python object, you use the `convert_to_obj` function.\n\n### Usage\n`convert_to_obj(data, allow_mode_repr=True, _reached=None)`\n\n### Arguments\n\nArgument   | Type       | Description | Default Value\n---------- | ---------- | ----------- | -----------\ndata | Mapping | The mapping to convert back to a Python object (a `dict` is a mapping) | required\nallow_mode_repr | bool | Whether to enable MODE_REPR; you might want to have this enabled because the deserialization function of MODE_REPR uses `eval` which is insecure | True\n_reached | Set | A value passed to the function internally for recursive data structures | None\n\n### Example\n\n``` python\n\u003e\u003e\u003e data = {'version': 1, 'min_version': 1, 'module': '__main__', 'type': 'A', 'attrs': {'obj': {'value': 'Hello World!', 'uuid': 192575949315149374534195982055635280394, 'mode': 'fallback'}}, 'uuid': 192575949235921212021180267458779800074}\n\u003e\u003e\u003e obj2 = convert_to_obj(data)\n\u003e\u003e\u003e obj2\n\u003c__main__.A at 0x2473cbb88e0\u003e\n```\n\n## Storing and Reading JSON\nTo store and read JSON-serialized objects, you use the `dump`, `dumps`, `load`, and `loads` functions.\n\n### `dump` and `dumps`\nSerializes `obj` and passes `*jargs` and `**jkwargs` to `json.dump` and `json.dumps` respectively.\n\n### `load` and `loads`\nDeserializes the JSON data from `json.dump` or `json.dumps`. It passes `*jargs` and `**jkwargs` to `json.dump` and `json.dumps` respectively.\n\n## Modifying how the serializer serializes specific types\nTo modify how the serializer serializes specific types you use the `type_settings` descriptor.\n\n### Usage\n`@type_settings(serialization_mode=MODE_YES, serialization_function=None, deserialization_function=None)`\n\n### Arguments\n\nArgument   | Type       | Description | Default Value\n---------- | ---------- | ----------- | -----------\nserialization_mode | any of the MODE_* constants | The method used to serialize (and possibly deserialize the type) | MODE_YES\nserialization_function | Union[None, Callable[[object, Set], JsonSupported]] | The function to serialize with (for MODE_FUNCTION); or `None` for others | None\ndeserialization_function | Union[None, Callable[[JsonSupported, bool, Set], object]] | The function to serialize with (for MODE_FUNCTION); or `None` for others | None\n\n### Modes\n#### MODE_YES\nserialize the type\n#### MODE_NO\ndon't serialize the type, always deserializes as `None`\n#### MODE_FALLBACK\nfallback to the JSON module types, the types can be found at https://docs.python.org/3/library/json.html#json.JSONDecoder\n#### MODE_REPR\nserializes with `repr(obj)`, deserializes with `eval(data)`\n#### MODE_FUNCTION\nuses `serialization_function` to serialize, and `deserialization_function` to deserialize","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaming32%2Fjson-serialize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgaming32%2Fjson-serialize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaming32%2Fjson-serialize/lists"}