{"id":13737795,"url":"https://github.com/linkedin/python-avro-json-serializer","last_synced_at":"2025-08-17T01:34:59.875Z","repository":{"id":14524090,"uuid":"17238311","full_name":"linkedin/python-avro-json-serializer","owner":"linkedin","description":"Serializes data into a JSON format using AVRO schema.","archived":false,"fork":false,"pushed_at":"2022-01-13T17:01:00.000Z","size":40,"stargazers_count":137,"open_issues_count":5,"forks_count":45,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-05-08T15:42:46.629Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linkedin.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2014-02-27T05:50:14.000Z","updated_at":"2024-09-04T12:17:11.000Z","dependencies_parsed_at":"2022-07-12T15:13:20.359Z","dependency_job_id":null,"html_url":"https://github.com/linkedin/python-avro-json-serializer","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/linkedin/python-avro-json-serializer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkedin%2Fpython-avro-json-serializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkedin%2Fpython-avro-json-serializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkedin%2Fpython-avro-json-serializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkedin%2Fpython-avro-json-serializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linkedin","download_url":"https://codeload.github.com/linkedin/python-avro-json-serializer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkedin%2Fpython-avro-json-serializer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270796217,"owners_count":24647319,"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","status":"online","status_checked_at":"2025-08-16T02:00:11.002Z","response_time":91,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-08-03T03:02:01.283Z","updated_at":"2025-08-17T01:34:59.849Z","avatar_url":"https://github.com/linkedin.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"Python Avro JSON serializer\n================\n\n[![PyPI version](https://badge.fury.io/py/avro_json_serializer.png)](http://badge.fury.io/py/avro_json_serializer)\n\n[AvroJsonSerializer](avro_json_serializer/__init__.py#L28) serializes data into a JSON format using AVRO schema.\n\nWhy do we need serializer instead of just dumping into JSON?\n* validation that your data matches the schema\n* serialization of unions (see [SimpleExample](#simple-example) below)\n* some Avro JSON deserializers expect fields in JSON in the same order as in the schema\n* serialization of `bytes` and `fixed` fields\n\nBinary distribution can be found on [pypi](https://pypi.python.org/pypi/avro_json_serializer/).\n\n## Simple example:\n\n```python\n\nschema_dict = {\n    \"namespace\": \"example.avro\",\n          \"type\": \"record\",\n          \"name\": \"User\",\n          \"fields\": [\n              {\"name\": \"name\", \"type\": \"string\"},\n              {\"name\": \"favorite_number\",  \"type\": [\"int\", \"null\"]},\n              {\"name\": \"favorite_color\", \"type\": [\"string\", \"null\"]}\n          ]\n}\navro_schema = avro.schema.make_avsc_object(schema_dict, avro.schema.Names())\nserializer = AvroJsonSerializer(avro_schema)\n\nself.assertEquals(serializer.to_json({\"name\": \"Alyssa\", \"favorite_number\": 256}),\n                  \"\"\"{\"name\":\"Alyssa\",\"favorite_number\":{\"int\":256},\"favorite_color\":null}\"\"\")\n\nself.assertEquals(serializer.to_json({\"name\": \"Ben\", \"favorite_number\": 7, \"favorite_color\": \"red\"}),\n                  \"\"\"{\"name\":\"Ben\",\"favorite_number\":{\"int\":7},\"favorite_color\":{\"string\":\"red\"}}\"\"\")\n\nself.assertEquals(serializer.to_json({\"name\": \"Lion\"}),\n                  \"\"\"{\"name\":\"Lion\",\"favorite_number\":null,\"favorite_color\":null}\"\"\")\n```\n\n## Another example:\n\n```python\n\n# need to serialize this data\ndata = {\n    \"ffloat\": 1.0,\n    \"funion_null\": None,\n    \"flong\": 1L,\n    \"fdouble\": 2.0,\n    \"ffixed\": \"1234567890123456\",\n    \"fint\": 1,\n    \"fstring\": \"hi there\",\n    \"frec\": {\n        \"subfint\": 2\n    }\n}\n\n# according to this schema:\n\nschema_dict = {\n    \"fields\": [{\"name\": \"fint\", \"type\": \"int\"},\n            {\"name\": \"flong\", \"type\": \"long\"},\n            {\"name\": \"fstring\", \"type\": \"string\"},\n            {\"name\": \"ffixed\",\n             \"size\": 16,\n             \"type\": {\"name\": \"fixed_16\", \"size\": 16, \"type\": \"fixed\"}},\n            {\"name\": \"frec\",\n             \"type\": {\"fields\": [{\"name\": \"subfint\", \"type\": \"int\"}],\n                      \"name\": \"Rec\",\n                      \"type\": \"record\"}},\n            {\"name\": \"funion_null\", \"type\": [\"int\", \"null\"]},\n            {\"name\": \"ffloat\", \"type\": \"float\"},\n            {\"name\": \"fdouble\", \"type\": \"double\"}],\n    \"name\": \"all_field\",\n    \"namespace\": \"com.some.thing\",\n    \"type\": \"record\"\n}\n\navro_schema = avro.schema.make_avsc_object(schema_dict, avro.schema.Names())\n\nserializer = AvroJsonSerializer(avro_schema)\njson_str = serializer.to_json(data)\n\nprint json_str\n\u003e {\"fint\":1,\"flong\":1,\"fstring\":\"hi there\",\"ffixed\":\"1234567890123456\",\"frec\":{\"subfint\":2},\"funion_null\":null,\"ffloat\":1.0,\"fdouble\":2.0}\n\n```\n\nSee [tests](avro_json_serializer/test/test_avro_json_serializer.py) for more examples.\n\n\n## How to run tests\n```bash\npython-avro-json-serializer$ virtualenv venv\npython-avro-json-serializer$ source venv/bin/activate\n(venv)python-avro-json-serializer$ pip install tox\n(venv)python-avro-json-serializer$ tox\nGLOB sdist-make: /Users/bngo/python-avro-json-serializer/setup.py\npy27 create: /Users/bngo/python-avro-json-serializer/.tox/py27\npy27 installdeps: nose, -rrequirements.txt\npy27 inst: /Users/bngo/python-avro-json-serializer/.tox/dist/avro_json_serializer-0.4.1.zip\npy27 installed: avro==1.7.6,avro-json-serializer==0.4.1,nose==1.3.7,simplejson==3.8.2,six==1.10.0\npy27 runtests: PYTHONHASHSEED='107331485'\npy27 runtests: commands[0] | nosetests\n.............\n----------------------------------------------------------------------\nRan 13 tests in 0.066s\n\nOK\npy35 create: /Users/bngo/python-avro-json-serializer/.tox/py35\npy35 installdeps: nose, -rrequirements.txt\npy35 inst: /Users/bngo/python-avro-json-serializer/.tox/dist/avro_json_serializer-0.4.1.zip\npy35 installed: avro-json-serializer==0.4.1,avro-python3==1.8.1,nose==1.3.7,simplejson==3.8.2,six==1.10.0\npy35 runtests: PYTHONHASHSEED='107331485'\npy35 runtests: commands[0] | nosetests\n.............\n----------------------------------------------------------------------\nRan 13 tests in 0.029s\n\nOK\n_____________________________________________________________________________________ summary _____________________________________________________________________________________\n  py27: commands succeeded\n  py35: commands succeeded\n  congratulations :)\n```\n\n## License\n\nPython Avro JSON serializer is licensed under the terms of the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkedin%2Fpython-avro-json-serializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinkedin%2Fpython-avro-json-serializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkedin%2Fpython-avro-json-serializer/lists"}