json2schema


Namejson2schema JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/hanzhichao/json2schema
SummaryJSON to JSONSchema
upload_time2023-06-17 13:41:22
maintainer
docs_urlNone
authorHan Zhichao
requires_python
licenseMIT license
keywords json2schema jsonschema json to jsonschema
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # json2schema

Get (Guess) jsonschema from one json sample

## Features

- json to jsonschema

## Install

```
$ pip install json2schema
```

## Use

### Simple Use

```python
from json2schema import json2schema
from pprint import pprint

data = {
    "first_name": "George",
    "last_name": "Washington",
    "birthday": "1732-02-22",
    "address": {
        "street_address": "3200 Mount Vernon Memorial Highway",
        "city": "Mount Vernon",
        "state": "Virginia",
        "country": "United States"
    }
}

schema = json2schema(data)
pprint(schema)

```
output

```shell
{'$schema': 'http://json-schema.org/schema',
 'properties': {'address': {'properties': {'city': {'type': 'string'},
                                           'country': {'type': 'string'},
                                           'state': {'type': 'string'},
                                           'street_address': {'type': 'string'}},
                            'required': ['street_address',
                                         'city',
                                         'state',
                                         'country'],
                            'type': 'object'},
                'birthday': {'type': 'string'},
                'first_name': {'type': 'string'},
                'last_name': {'type': 'string'}},
 'required': ['first_name', 'last_name', 'birthday', 'address'],
 'type': 'object'}
```

### More arguments

You can use `required_all=True` to mark all properties or items as required
with `schema = json2schema(data, required_all=True)` you will get 
```shell
{'$schema': 'http://json-schema.org/schema',
 'properties': {'address': {'properties': {'city': {'type': 'string'},
                                           'country': {'type': 'string'},
                                           'state': {'type': 'string'},
                                           'street_address': {'type': 'string'}},
                            'required': ['street_address',
                                         'city',
                                         'state',
                                         'country'],
                            'type': 'object'},
                'birthday': {'type': 'string'},
                'first_name': {'type': 'string'},
                'last_name': {'type': 'string'}},
 'required': ['first_name', 'last_name', 'birthday', 'address'],
 'type': 'object'}
```
or use `check_value=True` to mark all value exact the same with the sample data
with `schema = json2schema(data, check_value=True)`, you will get
```shell
{'$schema': 'http://json-schema.org/schema',
 'properties': {'address': {'properties': {'city': {'pattern': '^Mount Vernon$',
                                                    'type': 'string'},
                                           'country': {'pattern': '^United '
                                                                  'States$',
                                                       'type': 'string'},
                                           'state': {'pattern': '^Virginia$',
                                                     'type': 'string'},
                                           'street_address': {'pattern': '^3200 '
                                                                         'Mount '
                                                                         'Vernon '
                                                                         'Memorial '
                                                                         'Highway$',
                                                              'type': 'string'}},
                            'required': ['street_address',
                                         'city',
                                         'state',
                                         'country'],
                            'type': 'object'},
                'birthday': {'pattern': '^1732-02-22$', 'type': 'string'},
                'first_name': {'pattern': '^George$', 'type': 'string'},
                'last_name': {'pattern': '^Washington$', 'type': 'string'}},
 'required': ['first_name', 'last_name', 'birthday', 'address'],
 'type': 'object'}
 ```

## TODO:
- [ ] get jsonschema with multiple samples
- [ ] more args for json2schema

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hanzhichao/json2schema",
    "name": "json2schema",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "json2schema,jsonschema,json to jsonschema",
    "author": "Han Zhichao",
    "author_email": "superhin@126.com",
    "download_url": "https://files.pythonhosted.org/packages/33/06/2b98d8b35b3730f140822ecf5937386446e33d8c8a072724745b81f24618/json2schema-0.1.1.tar.gz",
    "platform": null,
    "description": "# json2schema\n\nGet (Guess) jsonschema from one json sample\n\n## Features\n\n- json to jsonschema\n\n## Install\n\n```\n$ pip install json2schema\n```\n\n## Use\n\n### Simple Use\n\n```python\nfrom json2schema import json2schema\nfrom pprint import pprint\n\ndata = {\n    \"first_name\": \"George\",\n    \"last_name\": \"Washington\",\n    \"birthday\": \"1732-02-22\",\n    \"address\": {\n        \"street_address\": \"3200 Mount Vernon Memorial Highway\",\n        \"city\": \"Mount Vernon\",\n        \"state\": \"Virginia\",\n        \"country\": \"United States\"\n    }\n}\n\nschema = json2schema(data)\npprint(schema)\n\n```\noutput\n\n```shell\n{'$schema': 'http://json-schema.org/schema',\n 'properties': {'address': {'properties': {'city': {'type': 'string'},\n                                           'country': {'type': 'string'},\n                                           'state': {'type': 'string'},\n                                           'street_address': {'type': 'string'}},\n                            'required': ['street_address',\n                                         'city',\n                                         'state',\n                                         'country'],\n                            'type': 'object'},\n                'birthday': {'type': 'string'},\n                'first_name': {'type': 'string'},\n                'last_name': {'type': 'string'}},\n 'required': ['first_name', 'last_name', 'birthday', 'address'],\n 'type': 'object'}\n```\n\n### More arguments\n\nYou can use `required_all=True` to mark all properties or items as required\nwith `schema = json2schema(data, required_all=True)` you will get \n```shell\n{'$schema': 'http://json-schema.org/schema',\n 'properties': {'address': {'properties': {'city': {'type': 'string'},\n                                           'country': {'type': 'string'},\n                                           'state': {'type': 'string'},\n                                           'street_address': {'type': 'string'}},\n                            'required': ['street_address',\n                                         'city',\n                                         'state',\n                                         'country'],\n                            'type': 'object'},\n                'birthday': {'type': 'string'},\n                'first_name': {'type': 'string'},\n                'last_name': {'type': 'string'}},\n 'required': ['first_name', 'last_name', 'birthday', 'address'],\n 'type': 'object'}\n```\nor use `check_value=True` to mark all value exact the same with the sample data\nwith `schema = json2schema(data, check_value=True)`, you will get\n```shell\n{'$schema': 'http://json-schema.org/schema',\n 'properties': {'address': {'properties': {'city': {'pattern': '^Mount Vernon$',\n                                                    'type': 'string'},\n                                           'country': {'pattern': '^United '\n                                                                  'States$',\n                                                       'type': 'string'},\n                                           'state': {'pattern': '^Virginia$',\n                                                     'type': 'string'},\n                                           'street_address': {'pattern': '^3200 '\n                                                                         'Mount '\n                                                                         'Vernon '\n                                                                         'Memorial '\n                                                                         'Highway$',\n                                                              'type': 'string'}},\n                            'required': ['street_address',\n                                         'city',\n                                         'state',\n                                         'country'],\n                            'type': 'object'},\n                'birthday': {'pattern': '^1732-02-22$', 'type': 'string'},\n                'first_name': {'pattern': '^George$', 'type': 'string'},\n                'last_name': {'pattern': '^Washington$', 'type': 'string'}},\n 'required': ['first_name', 'last_name', 'birthday', 'address'],\n 'type': 'object'}\n ```\n\n## TODO:\n- [ ] get jsonschema with multiple samples\n- [ ] more args for json2schema\n",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "JSON to JSONSchema",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/hanzhichao/json2schema"
    },
    "split_keywords": [
        "json2schema",
        "jsonschema",
        "json to jsonschema"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6783eabc118b2bd5e893a2e5a0b33a8c112ba540071f4c6dec714cc1e439e390",
                "md5": "5fd2d23b3fef057ee1704fcdfb9b25ac",
                "sha256": "cb08d13893e8582f29a3b4f01b9c381742890c98d22b8dd7693cffb1f38047c2"
            },
            "downloads": -1,
            "filename": "json2schema-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5fd2d23b3fef057ee1704fcdfb9b25ac",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5003,
            "upload_time": "2023-06-17T13:41:20",
            "upload_time_iso_8601": "2023-06-17T13:41:20.693821Z",
            "url": "https://files.pythonhosted.org/packages/67/83/eabc118b2bd5e893a2e5a0b33a8c112ba540071f4c6dec714cc1e439e390/json2schema-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "33062b98d8b35b3730f140822ecf5937386446e33d8c8a072724745b81f24618",
                "md5": "a6dfdd659a117f02be1a5de142962509",
                "sha256": "66efec8f389fcab2391810ce3bc6dcc32111c48a4d146c50d95be7b6b06fb860"
            },
            "downloads": -1,
            "filename": "json2schema-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "a6dfdd659a117f02be1a5de142962509",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5441,
            "upload_time": "2023-06-17T13:41:22",
            "upload_time_iso_8601": "2023-06-17T13:41:22.461044Z",
            "url": "https://files.pythonhosted.org/packages/33/06/2b98d8b35b3730f140822ecf5937386446e33d8c8a072724745b81f24618/json2schema-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-17 13:41:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hanzhichao",
    "github_project": "json2schema",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "json2schema"
}
        
Elapsed time: 0.10819s