{ "info": { "author": "Avi SZYCHTER", "author_email": "xentsc2@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "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> 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>>> print(user)\n,\n \"username\": , \"age\": , \"isAdmin\": }>\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>>> 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)", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/xatavian/easyjsonparser", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "easyjsonparser", "package_url": "https://pypi.org/project/easyjsonparser/", "platform": "", "project_url": "https://pypi.org/project/easyjsonparser/", "project_urls": { "Homepage": "https://github.com/xatavian/easyjsonparser" }, "release_url": "https://pypi.org/project/easyjsonparser/1.1.1/", "requires_dist": null, "requires_python": "", "summary": "Serialize and deserialize JSON documents to Python data structures", "version": "1.1.1" }, "last_serial": 5407120, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "ccf14aebaf1dfdb0de80fa606af7d406", "sha256": "5b858da2037abd8bb066a2df18dc30007a5c075c7955ce5bf4c39f5e78a0922e" }, "downloads": -1, "filename": "easyjsonparser-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "ccf14aebaf1dfdb0de80fa606af7d406", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 13185, "upload_time": "2019-06-13T07:37:56", "url": "https://files.pythonhosted.org/packages/80/a5/14dfd065b8df7c4b6b34da909803a4464ef1d46f7f14b9533f848eb15b83/easyjsonparser-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "619a7d81e4ff1f8413078a79dfde8d90", "sha256": "a4491144a397914324f87b5185a151e4c59d769cceb623e115562170fc7a06a2" }, "downloads": -1, "filename": "easyjsonparser-1.0.0.tar.gz", "has_sig": false, "md5_digest": "619a7d81e4ff1f8413078a79dfde8d90", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9810, "upload_time": "2019-06-13T07:38:02", "url": "https://files.pythonhosted.org/packages/ce/88/5e8c3561feee46ff2f8d0a8439d0e990015daf9cc44c268c2914f0b0d90a/easyjsonparser-1.0.0.tar.gz" } ], "1.0.0b0": [ { "comment_text": "", "digests": { "md5": "83804e3797f9da6836b8bf61a40295ef", "sha256": "111685c3673301c0886c9e75c25766a05dd435e78cc1654df0bbb2a3d412c18c" }, "downloads": -1, "filename": "easyjsonparser-1.0.0b0-py3-none-any.whl", "has_sig": false, "md5_digest": "83804e3797f9da6836b8bf61a40295ef", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 13227, "upload_time": "2019-06-15T07:29:52", "url": "https://files.pythonhosted.org/packages/ce/34/a6357191e45b3a32aee366133a495e158b0f53a9b0b0168ebb163c4a9fe8/easyjsonparser-1.0.0b0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "55f35bd155294753fcfa90e57f77a371", "sha256": "5f4b482019af59a3888846ac4eb21360dfa50c6f3e7c8b98de86a803fdbd850a" }, "downloads": -1, "filename": "easyjsonparser-1.0.0b0.tar.gz", "has_sig": false, "md5_digest": "55f35bd155294753fcfa90e57f77a371", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11489, "upload_time": "2019-06-15T07:29:54", "url": "https://files.pythonhosted.org/packages/6c/70/b3eb03b1226d62f0eaf6a82078cfaa1f961254ea1e7a61a598796fd59c21/easyjsonparser-1.0.0b0.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "929b247b0bb44f14a12be4061cdaae83", "sha256": "100a6be31dbe03aef6a9301d47a2fe2c55460392c00da692699148b07d94e17d" }, "downloads": -1, "filename": "easyjsonparser-1.1.0.tar.gz", "has_sig": false, "md5_digest": "929b247b0bb44f14a12be4061cdaae83", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11433, "upload_time": "2019-06-15T21:39:59", "url": "https://files.pythonhosted.org/packages/d7/52/650ce6d1824f9ef8d1a631acbd600cbd0410c7141060d32851ca24d87c02/easyjsonparser-1.1.0.tar.gz" } ], "1.1.0.post1": [ { "comment_text": "", "digests": { "md5": "d5a8aa6c9956f9c0b7081139e6caba88", "sha256": "05d69d9105627edcc1acfe1bf2d644c1b2ebd4af0196dcf11a85ca5434bc3d88" }, "downloads": -1, "filename": "easyjsonparser-1.1.0.post1.tar.gz", "has_sig": false, "md5_digest": "d5a8aa6c9956f9c0b7081139e6caba88", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11482, "upload_time": "2019-06-16T07:04:07", "url": "https://files.pythonhosted.org/packages/01/e1/577076fe23d33afcc7d00f0b9b372a5cd17de78924c602f43ebcbc0bbb75/easyjsonparser-1.1.0.post1.tar.gz" } ], "1.1.0.post2": [ { "comment_text": "", "digests": { "md5": "17416093b07355dec460ac0060e9874a", "sha256": "4b14abfd787c34c6279da2ee1c40d6c907eb9d6317ca8f7f4ad797d2b9a94c87" }, "downloads": -1, "filename": "easyjsonparser-1.1.0.post2.tar.gz", "has_sig": false, "md5_digest": "17416093b07355dec460ac0060e9874a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11484, "upload_time": "2019-06-16T07:26:19", "url": "https://files.pythonhosted.org/packages/c8/41/c820da77634e9bb9f7f35dca64dc78c9366cdf57d47a29162221e5f3c939/easyjsonparser-1.1.0.post2.tar.gz" } ], "1.1.1": [ { "comment_text": "", "digests": { "md5": "e726333ce686dfaafdc2fb5fea2d20ff", "sha256": "37df8afda0dea07a5e4b655d6685b2dbf594ff4d045e86fe638de17268d53847" }, "downloads": -1, "filename": "easyjsonparser-1.1.1.tar.gz", "has_sig": false, "md5_digest": "e726333ce686dfaafdc2fb5fea2d20ff", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11662, "upload_time": "2019-06-16T18:00:34", "url": "https://files.pythonhosted.org/packages/ab/47/e733b2781207851c1883383ab4c1e6d88175b403587d9375819346a9bcaf/easyjsonparser-1.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e726333ce686dfaafdc2fb5fea2d20ff", "sha256": "37df8afda0dea07a5e4b655d6685b2dbf594ff4d045e86fe638de17268d53847" }, "downloads": -1, "filename": "easyjsonparser-1.1.1.tar.gz", "has_sig": false, "md5_digest": "e726333ce686dfaafdc2fb5fea2d20ff", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11662, "upload_time": "2019-06-16T18:00:34", "url": "https://files.pythonhosted.org/packages/ab/47/e733b2781207851c1883383ab4c1e6d88175b403587d9375819346a9bcaf/easyjsonparser-1.1.1.tar.gz" } ] }