All Projects → jazzband → Jsonmodels

jazzband / Jsonmodels

Licence: bsd-3-clause
jsonmodels is library to make it easier for you to deal with structures that are converted to, or read from JSON.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Jsonmodels

Coolie
Coolie(苦力) helps you to create models (& their constructors) from a JSON file.
Stars: ✭ 508 (+93.89%)
Mutual labels:  json, models
Acts as api
makes creating API responses in Rails easy and fun
Stars: ✭ 506 (+93.13%)
Mutual labels:  json, models
Plank
A tool for generating immutable model objects
Stars: ✭ 449 (+71.37%)
Mutual labels:  json, models
Api Client Generator
Angular REST API client generator from Swagger YAML or JSON file with camel case settigs
Stars: ✭ 92 (-64.89%)
Mutual labels:  json, models
Php Curl Class
PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs
Stars: ✭ 2,903 (+1008.02%)
Mutual labels:  json
Rinno
How to install local shiny apps
Stars: ✭ 255 (-2.67%)
Mutual labels:  json
Lazer Database
PHP flat file database to store data with JSON
Stars: ✭ 254 (-3.05%)
Mutual labels:  json
apple-receipt
Apple InAppPurchase Receipt - Models, Parser, Validator
Stars: ✭ 25 (-90.46%)
Mutual labels:  models
Sqawk
Like Awk but with SQL and table joins
Stars: ✭ 263 (+0.38%)
Mutual labels:  json
Tableexport
tableExport(table导出文件,支持json、csv、txt、xml、word、excel、image、pdf)
Stars: ✭ 261 (-0.38%)
Mutual labels:  json
Diffson
A scala diff/patch library for Json
Stars: ✭ 258 (-1.53%)
Mutual labels:  json
Naza
🍀 Go basic library. || Go语言基础库
Stars: ✭ 253 (-3.44%)
Mutual labels:  json
Json
An efficient JSON decoder
Stars: ✭ 260 (-0.76%)
Mutual labels:  json
Cloud Reports
Scans your AWS cloud resources and generates reports. Check out free hosted version:
Stars: ✭ 255 (-2.67%)
Mutual labels:  json
Restful Doom
HTTP+JSON API hosted inside the 1993 DOOM engine!
Stars: ✭ 263 (+0.38%)
Mutual labels:  json
thelper
Training framework & tools for PyTorch-based machine learning projects.
Stars: ✭ 14 (-94.66%)
Mutual labels:  models
Play Json
The Play JSON library
Stars: ✭ 254 (-3.05%)
Mutual labels:  json
Streaming Json Encoder
PHP library for iteratively encoding large JSON documents piece by piece
Stars: ✭ 260 (-0.76%)
Mutual labels:  json
Temme
📄 Concise selector to extract JSON from HTML.
Stars: ✭ 257 (-1.91%)
Mutual labels:  json
Safrs
SqlAlchemy Flask-Restful Swagger Json:API OpenAPI
Stars: ✭ 255 (-2.67%)
Mutual labels:  json

=========== JSON models

.. image:: https://jazzband.co/static/img/badge.svg :target: https://jazzband.co/ :alt: Jazzband

.. image:: https://badge.fury.io/py/jsonmodels.svg :target: http://badge.fury.io/py/jsonmodels

.. image:: https://github.com/jazzband/jsonmodels/workflows/Test/badge.svg :target: https://github.com/jazzband/jsonmodels/actions :alt: Tests

.. image:: https://img.shields.io/pypi/dm/jsonmodels.svg :target: https://pypi.python.org/pypi/jsonmodels :alt: PyPI

.. image:: https://codecov.io/gh/jazzband/jsonmodels/branch/master/graph/badge.svg :target: https://codecov.io/gh/jazzband/jsonmodels :alt: Coverage

jsonmodels is library to make it easier for you to deal with structures that are converted to, or read from JSON.

Features

  • Fully tested with Python 3.6+.

  • Support for PyPy (see implementation notes in docs for more details).

  • Create Django-like models:

    .. code-block:: python

    from jsonmodels import models, fields, errors, validators

    class Cat(models.Base):

      name = fields.StringField(required=True)
      breed = fields.StringField()
      love_humans = fields.IntField(nullable=True)
    

    class Dog(models.Base):

      name = fields.StringField(required=True)
      age = fields.IntField()
    

    class Car(models.Base):

      registration_number = fields.StringField(required=True)
      engine_capacity = fields.FloatField()
      color = fields.StringField()
    

    class Person(models.Base):

      name = fields.StringField(required=True)
      surname = fields.StringField(required=True)
      nickname = fields.StringField(nullable=True)
      car = fields.EmbeddedField(Car)
      pets = fields.ListField([Cat, Dog], nullable=True)
    
  • Access to values through attributes:

    .. code-block:: python

    cat = Cat() cat.populate(name='Garfield') cat.name 'Garfield' cat.breed = 'mongrel' cat.breed 'mongrel'

  • Validate models:

    .. code-block:: python

    person = Person(name='Chuck', surname='Norris') person.validate() None

    dog = Dog() dog.validate() *** ValidationError: Field "name" is required!

  • Cast models to python struct and JSON:

    .. code-block:: python

    cat = Cat(name='Garfield') dog = Dog(name='Dogmeat', age=9) car = Car(registration_number='ASDF 777', color='red') person = Person(name='Johny', surname='Bravo', pets=[cat, dog]) person.car = car person.to_struct() { 'car': { 'color': 'red', 'registration_number': 'ASDF 777' }, 'surname': 'Bravo', 'name': 'Johny', 'nickname': None, 'pets': [ {'name': 'Garfield'}, {'age': 9, 'name': 'Dogmeat'} ] }

    import json person_json = json.dumps(person.to_struct())

  • You don't like to write JSON Schema? Let jsonmodels do it for you:

    .. code-block:: python

    person = Person() person.to_json_schema() { 'additionalProperties': False, 'required': ['surname', 'name'], 'type': 'object', 'properties': { 'car': { 'additionalProperties': False, 'required': ['registration_number'], 'type': 'object', 'properties': { 'color': {'type': 'string'}, 'engine_capacity': {'type': ''}, 'registration_number': {'type': 'string'} } }, 'surname': {'type': 'string'}, 'name': {'type': 'string'}, 'nickname': {'type': ['string', 'null']} 'pets': { 'items': { 'oneOf': [ { 'additionalProperties': False, 'required': ['name'], 'type': 'object', 'properties': { 'breed': {'type': 'string'}, 'name': {'type': 'string'} } }, { 'additionalProperties': False, 'required': ['name'], 'type': 'object', 'properties': { 'age': {'type': 'number'}, 'name': {'type': 'string'} } }, { 'type': 'null' } ] }, 'type': 'array' } } }

  • Validate models and use validators, that affect generated schema:

    .. code-block:: python

    class Person(models.Base): ... ... name = fields.StringField( ... required=True, ... validators=[ ... validators.Regex('^[A-Za-z]+$'), ... validators.Length(3, 25), ... ], ... ) ... age = fields.IntField( ... nullable=True, ... validators=[ ... validators.Min(18), ... validators.Max(101), ... ] ... ) ... nickname = fields.StringField( ... required=True, ... nullable=True ... ) ...

    person = Person() person.age = 11 person.validate() *** ValidationError: '11' is lower than minimum ('18'). person.age = None person.validate() None

    person.age = 19 person.name = 'Scott_' person.validate() *** ValidationError: Value "Scott_" did not match pattern "^[A-Za-z]+$".

    person.name = 'Scott' person.validate() None

    person.nickname = None person.validate() *** ValidationError: Field is required!

    person.to_json_schema() { "additionalProperties": false, "properties": { "age": { "maximum": 101, "minimum": 18, "type": ["number", "null"] }, "name": { "maxLength": 25, "minLength": 3, "pattern": "/^[A-Za-z]+$/", "type": "string" }, "nickname": {, "type": ["string", "null"] } }, "required": [ "nickname", "name" ], "type": "object" }

    For more information, please see topic about validation in documentation.

  • Lazy loading, best for circular references:

    .. code-block:: python

    class Primary(models.Base): ... ... name = fields.StringField() ... secondary = fields.EmbeddedField('Secondary')

    class Secondary(models.Base): ... ... data = fields.IntField() ... first = fields.EmbeddedField('Primary')

    You can use either Model, full path path.to.Model or relative imports .Model or ...Model.

  • Using definitions to generate schema for circular references:

    .. code-block:: python

    class File(models.Base): ... ... name = fields.StringField() ... size = fields.FloatField()

    class Directory(models.Base): ... ... name = fields.StringField() ... children = fields.ListField(['Directory', File])

    class Filesystem(models.Base): ... ... name = fields.StringField() ... children = fields.ListField([Directory, File])

    Filesystem.to_json_schema() { "type": "object", "properties": { "name": {"type": "string"} "children": { "items": { "oneOf": [ "#/definitions/directory", "#/definitions/file" ] }, "type": "array" } }, "additionalProperties": false, "definitions": { "directory": { "additionalProperties": false, "properties": { "children": { "items": { "oneOf": [ "#/definitions/directory", "#/definitions/file" ] }, "type": "array" }, "name": {"type": "string"} }, "type": "object" }, "file": { "additionalProperties": false, "properties": { "name": {"type": "string"}, "size": {"type": "number"} }, "type": "object" } } }

  • Compare JSON schemas:

    .. code-block:: python

    from jsonmodels.utils import compare_schemas schema1 = {'type': 'object'} schema2 = {'type': 'array'} compare_schemas(schema1, schema1) True compare_schemas(schema1, schema2) False

More

For more examples and better description see full documentation: http://jsonmodels.rtfd.org.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].