Ian Lewis
Ian Lewis is a web developer living in Tokyo Japan. His current interests are in Django, python, alternative databases and rapid web application development. About Me...
  • jsonschema 0.2 alpha

    I just released a new version of jsonschema 0.2 alpha over at http://code.google.com/p/jsonschema

    The source can be downloaded here: jsonschema-0.2a.tar.gz
    The documentation can be found here: jsonschema (version 0.2a) documentation

    The new release includes the following notable changes.

    • The additionalProperties attribute is now validated.
    • Using schemas in the type attribute now works properly.
    • Changed support for unique attribute to the "identity" attribute (Note: this is not a backwards compatible change)
    • Fixed a bug where the original schema object/dictionary was modified by the validator
    • Added a new "interactive mode" which will add default values to objects if not specified as readonly by the schema
    • Made error messages a bit more friendly.
    • Fixed bugs with validating Unicode strings

    The additionalProperties attribute is used to define the format of additional properties that aren't explicitly specified in the properties attribute. This is useful for json like

    {
      bob: 10,
      sue: 20,
      bill: 30
    }

    where you have some things like game scores and the name of the attribute is someone's name which can't be defined in schema. You can use it like so:

    {
      "type": "object",
      "additionalProperties": "integer"
    }

    The type field was also fixed so that it handles adding schemas as types, so now you can define,

    {
      "type": [
        { "type": "array""minItems": 10 },
        { "type": "string", "pattern": "^0+$" }
      ]
    }

    This can let you define more complex types for use in schema.

    Send feedback このエントリーを含むはてなブックマーク はてなブックマーク - jsonschema 0.2 alpha
  • jsonschema mentioned on json.com

    Kris Zyp (the author of the JSONSchema proposal) mentioned jsonschema on his blog at json.com. Thanks Kris!!

    Send feedback このエントリーを含むはてなブックマーク はてなブックマーク - jsonschema mentioned on json.com
  • JSON Schema Validator 0.1a for Python

    I just released the first version for a project that I've been working on since the Python Onsen. It's a validator for JSON Schema written in Python. It's based on the JSON Schema Proposal Second Draft.

    The source can be downloaded here: jsonschema-0.1a.tar.gz
    The documentation can be found here: jsonschema (version 0.1a) documentation

    JSON Schema's purpose is to allow validation of JSON documents much like XML Schema, DTD. You can use it to define what kind of data should be present in the document as well as the structure of the data. You might have some JSON for a contact like so:

    {
      "name": "Ian Lewis",
      "email": "IanLewis@xyz.com",
      "address": "123 Main St.",
      "phone": "080-1942-9494"
    }

    And you could describe this in JSON Schema with the following:

    {
      "type":"object",
      "properties":{
        "name": {"type":"string"},
        "age": {"type":"int", "optional":True},
        "email": {
          "type":"string",
          "pattern":"^[A-Za-z0-9][A-Za-z0-9\.]*@([A-Za-z0-9]+\.)+[A-Za-z0-9]+$"
        },
        "address": {"type":"string"},
        "phone": {"type":"string"}
      }
    }

    This can be validated with something like the following Python code:

    import jsonschema, simplejson

    data = """{
      "name": "Ian Lewis",
      "email": "IanLewis@xyz.com",
      "address": "123 Main St.",
      "phone": "080-1942-9494"
    }"""

    schema = """{
      "type":"object",
      "properties":{
        "name": {"type":"string"},
        "age": {"type":"int", "optional":True},
        "email": {
          "type":"string",
          "pattern":"^[A-Za-z0-9][A-Za-z0-9\.]*@([A-Za-z0-9]+\.)+[A-Za-z0-9]+$"
        },
        "address": {"type":"string"},
        "phone": {"type":"string"}
      }
    }"""

    x = simplejson.loads(data)
    s = simplesjson.loads(schema)
    jsonschema.validate(x,s)

    It can be easily extended to include support for new properties or to override the default validation for standard properties so I think it could be used for a wide range of applications. I plan to use it for a Form Maker application (code) on GAE. Let me know what you think!

    Send feedback このエントリーを含むはてなブックマーク はてなブックマーク - JSON Schema Validator 0.1a for Python