{"id":13770811,"url":"https://github.com/wtsi-hgi/python-hgijson","last_synced_at":"2025-12-14T18:14:03.252Z","repository":{"id":62569073,"uuid":"50843981","full_name":"wtsi-hgi/python-hgijson","owner":"wtsi-hgi","description":"Python library for easily JSON encoding/decoding complex class-based Python models, using an arbitrarily complex (but easy to write!) mapping schema.","archived":false,"fork":false,"pushed_at":"2018-01-23T12:34:08.000Z","size":195,"stargazers_count":4,"open_issues_count":6,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T05:08:35.529Z","etag":null,"topics":["json","library","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wtsi-hgi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-01T14:17:17.000Z","updated_at":"2020-05-05T10:29:41.000Z","dependencies_parsed_at":"2022-11-03T17:15:21.134Z","dependency_job_id":null,"html_url":"https://github.com/wtsi-hgi/python-hgijson","commit_stats":null,"previous_names":["wtsi-hgi/python-json"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wtsi-hgi%2Fpython-hgijson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wtsi-hgi%2Fpython-hgijson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wtsi-hgi%2Fpython-hgijson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wtsi-hgi%2Fpython-hgijson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wtsi-hgi","download_url":"https://codeload.github.com/wtsi-hgi/python-hgijson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249010198,"owners_count":21197796,"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"],"created_at":"2024-08-03T17:00:42.345Z","updated_at":"2025-12-14T18:14:03.187Z","avatar_url":"https://github.com/wtsi-hgi.png","language":"Python","readme":"[![Build Status](https://travis-ci.org/wtsi-hgi/python-json.svg)](https://travis-ci.org/wtsi-hgi/python-json)\n[![codecov.io](https://codecov.io/gh/wtsi-hgi/python-json/graph/badge.svg)](https://codecov.io/gh/wtsi-hgi/python-json/)\n[![Documentation Status](https://readthedocs.org/projects/hgi-json/badge/?version=latest)](http://hgi-json.readthedocs.io/en/latest/?badge=latest)\n       \n\n# HGI JSON\nA Python 3 library for easily JSON encoding/decoding complex class-based Python models, using an arbitrarily complex \n(but easy to write!) mapping schema.\n\n\n## Features\n* Ability to create serializers and deserializers for complex class-based models using a mapping schema defined in \nPython.\n* Works seamlessly with Python's in-built `json.dumps` and `json.loads` serialization methods - does not require the use \nof exotic `convert_to_json`/`convert_from_json` methods.\n* Python models are not be coupled to the serialization process - models do not have to inherit from a particular\nsuperclass or implement an interface with a `to_json` (or similar) method.\n* JSON representations produced are not coupled to the Python model - an arbitrary mapping between the JSON and the\nmodel can be defined.\n* Simple to define serialization of subclasses, based on how superclasses are serialized.\n* Pure Python 3 - no DSL, XML or similar required to describe mappings, not using outdated Python 2.\n* [Well tested](https://codecov.io/gh/wtsi-hgi/python-json/).\n\n\n## Overview\n### Basic Steps\n1. Define schema for mapping an object to and/or from JSON representation using a list of `JsonPropertyMapping`\ndefinitions.\n2. Use `MappingJSONEncoderClassBuilder` with the mappings to build a subclass of `JSONEncode` for serializing instances \nof a specific type. Similar with decode.\n3. Use created encoder class with Python's in-built `json.dumps` via the `cls` parameter. Similar with decoder.\n\n\n### Defining Encoders/Decoders\nEncoders and decoders are generated based on a defined JSON \u003c-\u003e Model mapping. A mapping can be written that allows \ncomplex classes, such as that below, to be mapped to and from any JSON representation:\n```python\nclass CustomClass(SupportFor, MultipleInheritance):\n    self __init__(self, support_for_constructor_parameters):\n    self.support_for_all_types_of_properties = \"\"\n    self.including_sets = set()\n    self.and_lists = list()\n    self.and_dictionaries = dict()\n    self.and_complex_properties = ComplexClass()\n    self.and_nested_objects_of_the_same_type = CustomClass()\n    self.and_properties_not_in_json_if_none = None\n\n    self support_for_setters(self, value):\n        \"\"\"...\"\"\"\n\n    self support_for_getters(self):\n        \"\"\"...\"\"\"\n        \nCustomClassJSONEncoder = MappingJSONEncoderClassBuilder(...).build()    # type: JSONEncoder\nCustomClassJSONDecoder = MappingJSONDecoderClassBuilder(...).build()    # type: JSONDecoder\n\ncustom_class_as_json = json.dumps(custom_class, cls=CustomClassJSONEncoder)     # type: str\ncustom_class = json.loads(\"\u003ccustom_class_as_json\u003e\", cls=CustomClassJSONDecoder)     # type: CustomClass\n```\n\n## Documentation\nFor more details, including information on how to setup and use the library, please [view the documentation on \nReadTheDocs](http://hgi-json.readthedocs.io/en/latest/) or read it from `/docs`.\n","funding_links":[],"categories":["Model, Schema"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwtsi-hgi%2Fpython-hgijson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwtsi-hgi%2Fpython-hgijson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwtsi-hgi%2Fpython-hgijson/lists"}