{"id":44330029,"url":"https://github.com/xatavian/easyjsonparser","last_synced_at":"2026-02-11T09:09:08.670Z","repository":{"id":57425132,"uuid":"190085671","full_name":"xatavian/easyjsonparser","owner":"xatavian","description":"Easily serialize and deserialize JSON data from/to Python data structure","archived":false,"fork":false,"pushed_at":"2019-06-16T17:59:21.000Z","size":61,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-27T20:18:09.604Z","etag":null,"topics":["json","json-schema","parser-library","python"],"latest_commit_sha":null,"homepage":null,"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/xatavian.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":"2019-06-03T21:35:46.000Z","updated_at":"2024-05-13T01:50:54.000Z","dependencies_parsed_at":"2022-09-19T06:31:00.614Z","dependency_job_id":null,"html_url":"https://github.com/xatavian/easyjsonparser","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/xatavian/easyjsonparser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xatavian%2Feasyjsonparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xatavian%2Feasyjsonparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xatavian%2Feasyjsonparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xatavian%2Feasyjsonparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xatavian","download_url":"https://codeload.github.com/xatavian/easyjsonparser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xatavian%2Feasyjsonparser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29330858,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T06:13:03.264Z","status":"ssl_error","status_checked_at":"2026-02-11T06:12:55.843Z","response_time":97,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["json","json-schema","parser-library","python"],"created_at":"2026-02-11T09:09:07.834Z","updated_at":"2026-02-11T09:09:08.658Z","avatar_url":"https://github.com/xatavian.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"EasyJSONParser, a lightweight library for parsing and validating your\nJSON models\n=================================================================================\n\n[![Build Status](https://travis-ci.com/xatavian/easyjsonparser.svg?branch=master)](https://travis-ci.com/xatavian/easyjsonparser)\n\n\nModern Web frameworks all use ORM systems in order to achieve the\nserver-side actions on the database: for instance, Doctrine for Symfony3\n(PHP), Mongoose for MongoDB databases.\n\nORMs have the ability to read data and convert it into a collections of\nin-memory objects. They can also take a special object and convert it\nto the underlying storage format.\n\n**Motivation behind this project**\n\nWhile ORM-like systems are pretty common in Web development, they are\ninexistant for all other purposes. For instance, parsing a configuration\nfile (yeah, that's why I designed this library !) and validating its\ncontent, or outputting the configuration in a file.\n\n# Dependencies\n\nEasyJSONParser only uses the Python's standard library, especially the\n[`json`](https://docs.python.org/fr/3/library/json.html) module which\nserialize and unserialize the source/target data.\n\nEasyJSONParser is built for Python 3.\n\n# Installation\n\nGet the library from Pypi:\n\n```bash\n\u003e pip install easyjsonparser\n```\n\n# Basic examples\n\nIn this section, we will define dummy data structure `User` which follows the following schema:\n\n```json\n{\n    \"id\": \"xxx047AD_\",\n    \"username\": \"jsonisnice\",\n    \"age\": 16,\n    \"isAdmin\": false\n}\n```\n\n`EasyJSONParser` can extract parse the data string into an object with the following code:\n\n```python\nimport easyjsonparser as ejp\nfrom easyjsonparser.document import JSONObjectDocument\n\nclass User(JSONObjectDocument):\n    id = ejp.String()\n    username = ejp.String()\n    age = ejp.Integer()\n    isAdmin = ejp.Boolean()\n\n# In this example, the data string is directly\n# written in the code but it can have\n# various source such as reading a file...\ndata_string = \"\"\"\n...\n\"\"\"\n\nuser = User.loads(data_string)\n```\n\nWhat if you already have loaded your data into a dictionary ? Then, just use `load` instead of `loads`:\n\n```python\nuser = User.load({\n    \"id\": \"xxx047AD_\",\n    \"username\": \"jsonisnice\",\n    \"age\": 16,\n    \"isAdmin\": False\n})\n```\n\nWe can get a representation of our user instance by just printing it:\n```python\n\u003e\u003e\u003e print(user)\n\u003cJSON UserInstance: {\"id\": \u003cJSON Value StringInstance: \"xxx047AD_\"\u003e,\n \"username\": \u003cJSON Value StringInstance: \"jsonisnice\"\u003e, \"age\": \u003cJSON\n  Value IntegerInstance: 16\u003e, \"isAdmin\": \u003cJSON Value BoolInstance: False\u003e}\u003e\n```\n\nWhat if we now want to parse a list of `User` ?\n\n```python\nfrom easyjsonparser.document import JSONAArrayDocument\n\nclass UserList(JSONArrayDocument);\n    schema = User()\n\nusers = UserList.load([\n    { ... },\n    { ... }\n])\n```\n\nDocument-type objects (ie. the ones that inherit from either `JSONObjectDocument` or `JSONArrayDocument`) can be mixed into one another.\n\nThey also are a variety of types but but the top-level data structure must **always** be either a `JSONObjectDocument` or `JSONArrayDocument`.\n\nWell, now what if we want to turn it back to a JSON string ? Let's use `to_json()` !\n\n```python\n\u003e\u003e\u003e  user.to_json()\n'{\"id\": \"xxx047AD_\", \"username\": \"jsonisnice\", \"age\": 16, \"isAdmin\": False}'\n```\n# Documents\n\nDocuments are classes that inherits from either `JSONObjectDocument` or `JSONArrayDocument`. They are special kinds of `Object` and `Array` because they contain class methods used for parsing the data. They behave like normal `Object` and `Array` but have the capacity of being a top-level data structure.\n\nThe definition of a `JSONArrayDocument` is a little bit different than using a regular `ejp.Array()`: the schema must be defined as a class attribute instead of a constructor argument.\n\n```python\nclass StringList(JSONArrayDocument):\n    schema = String()\n```\n\nHere are the following special methods:\n\n**`JSONObjectDocument.load(obj=None)` (@classmethod)**\n\nCreates a `JSONObjectDocument` with input source `obj`. If no input is given, then an empty data structure is computed. If an input is given but is not a dictionnary, an exception is raised.\n\n**`JSONObjectDocument.loads(obj_string)` (@classmethod)**\n\nCreates a `JSONObjectDocument` from a string. The data is parsed to a dictionary using `json.loads()` from Python's standard library. If  `obj_string` does not repressent a valid JSON object, an exception is raised.\n\n**`JSONArrayDocument.load(*values)` (@classmethod)**\n\nCreates a `JSONArrayDocument` from a list of values. `values` can be a variadic array but it is also possible to pass a single input which must be a list or tuple.\n\n**`JSONArrayDocument.loads(array_string)` (@classmethod)**\n\nCreates a `JSONArrayDocument` from a string. The data is parsed to an array using `json.loads()` from Python's standard library. If `array_string` does not represent a valid JSON array, an exception is raised.\n\n# Available types\n\n## `ejp.String()`\n\nRepresents a JSON string.\n\n## `ejp.Integer()`\n\nRepresents a JSON integer.\n\n*Warning: boolean and floats are accepted as an input but they will be converted to integers with `int()`. A warning is raised when a conversion happens.\n\n*TODO: add an option to disable/enable this behaviour*\n\n## `ejp.Float()`\n\nRepresents a floating-point number. Conversion from integers and boolean work the way as `ejp.Integer()`\n\n## `ejp.Boolean()`\n\nRepresents a boolean. Conversion from floating-point numbers and boolean work the way as `ejp.Integer()`\n\n## `ejp.Null()`\n\nRepresents a `null` value. Every input that is not `None` (in Python) or `null`(as a JSON string) will raise a parsing exception.\n\n## `ejp.Object()`\n\nRepresents a JSON object.\n\nProperties cannot be defined in the constructor: they must be defined as class attributes as follows:\n\n```python\nclass MyObject(ejp.Object):\n    property1 = ejp.String()\n    property2 = ejp.Boolean()\n    ...\n```\n\n*Note: remember that you need to use `JSONObjectDocument` to define a top-level object*.\n\n## `ejp.Array()`\n\nRepresents a JSON array. An array must follow a schema which must be passed to the constructor of `ejp.Array()`. If the schema is invalid, an exception is raised.\n\n```python\nclass MyObject(ejp.Object):\n    array = ejp.Array(schema=String())\n```\n\n*Note: remember that you need to use `JSONArrayDocument` to define a top-level array*.\n\n## `ejp.Empty()`\n\nRepresents an empty value. Used for optional properties/values: if you want to clear the content of an optional parameter, set its value to `ejp.Empty()`.\n\n# License\n\nThis software is distributed under the [MIT license](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxatavian%2Feasyjsonparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxatavian%2Feasyjsonparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxatavian%2Feasyjsonparser/lists"}