{ "info": { "author": "Manuel Barkhau", "author_email": "mbarkhau@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: MacOS :: MacOS X", "Operating System :: POSIX", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Topic :: Utilities" ], "description": "KSON: Keystripped Schemafied Object Notation\n============================================\n\nKSON is a simple data interchange format based on JSON. Its serialized\nrepresentation doesn't contain the redundant keys of typical json \ndocuments and more compact representations of values are possible through\nan extensible encoding/decoding mechanism.\n\nKSON uses a simple schema format to describe arbitrarrily nested objects\nand encoded types. The minified and gzipped javascript library is < 1K.\n\n\nUsage in javascript\n-------------------\n\n // Load schema definitions\n\n var movie_schemas = [\n {\n \"id\": \"role\",\n \"fields\": [\"name\", \"character\"],\n \"meta\": [0, 0]\n },{\n \"id\": \"movie\",\n \"fields\": [\"title\", \"year\", \"rating\", \"cover\", \"actors\"],\n \"meta\": [0, 0, 0, \"prefix:http\\://movies.db/covers/|suffix.jpg\", \"[]role\"]\n }\n ];\n KSON.addSchema(movie_schemas);\n\n var movies = [\n {\n \"title\": \"Forrest Gump\",\n \"year\": 1994,\n \"rating\": 8.7,\n \"cover\": \"http://movies.db/covers/8.jpg\",\n \"actors\": [\n {\"name\": \"Tom Hanks\", \"character\": \"Forest Gump\"},\n {\"name\": \"Robin Wright\", \"character\": \"Jenny Curran\"},\n {\"name\": \"Gary Sinise\", \"character\": \"Lieutenant Dan Taylor\"}\n ]\n },\n {\n \"title\": \"Toy Story\",\n ...\n }\n ...\n ];\n\n // pretty printing is not part of the library\n console.log(KSON.stringify(movies, \"[]movie\"));\n [\n \"[]movie\",\n \"Forest Gump\",\n 1994,\n 8.7,\n \"8\",\n [\n [\"Tom Hanks\", \"Forest Gump\"],\n [\"Robin Wright\", \"Jenny Curran\"],\n [\"Gary Sinise\", \"Lieutenant Dan Taylor\"]\n ],\n \"Toy Story\",\n ...\n ]\n\n // Of course the \"movie\" and \"role\" schema definitions may also be\n // serialized to KSON using the \"schema\" schema:\n\n var schema_data = KSON.stringify(movie_schemas, \"[]schema\")\n console.log(schema_data);\n\n [\"[]schema\",\"role\",[\"name\",\"character\"],[0, 0],\"movie\",\n [\"title\",\"year\",\"rating\",\"cover\",\"actors\"],\n [0,0,0,\"prefix:http\\://movies.db/covers/|suffix:.jpg\",\"[]role\"]]\n\n // Likewise schemas can be initialized with a kson document\n KSON.addSchema(schema_data);\n\nFAQ\n---\n\nQ: Why should I use this instead of JSON/MessagePack/Thrift/...?\nA: Unless you are targeting the browser you probably shouldn't. If you\n are, then the size and speed of the javascript libraries for these\n formats may make KSON a favorable option.\n\nQ: Is KSON faster/smaller/better than JSON?\nA: Tests using node.js indicate that parsing is marginally slower. This\n should be outweighed by faster transmission speed of signifigantly less\n data. See the node.js benchmarks for more info.\n\nQ: Is this a drop in replacement for JSON?\nA: No, you will need to write schema definitions for your data. Automatic\n schema detection based on example data may help in getting started. Also\n see \"restrictions\" in the Specification.\n\nQ: Why yet another a schema format for JSON?\nA: Existing JSON schema formats include extrenious information to the\n purpose of KSON and would require larger javascript library for\n parsing and serialization.\n\nQ: Is there language support for php/ruby/java/c...?\nA: Currently javascript and python are supported. Porting to other\n languages with existing JSON support should be fairly easy and patches\n are very welcome.\n\n\nSchema Specification\n--------------------\n\nA KSON schema consists of three fields:\n id *string* identifier\n fields *array* of field names\n meta *array* signifying the types associated with\n corresponding elements in the *fields* array.\n\nA schema only defines one object. Nesting is accomplished by referencing\nsubschemas via their id in the meta array.\n\nAn element of *meta* specifies the content of the element of *fields* at\nthe same index. The lengths of the *fields* and *meta* arrays must be equal.\nAn element of *meta* must be one of the following:\n 0 field contains a plain value of type\n *string*, *boolean*, *number*, *null*.\n \"[]\" *array* of plain values\n \"schema-id\" *string* reference the schema of a nested object\n \"[]schema-id\" \n \"codec-id\"\n \"[]codec-id\"\n\n\nThe top level elements of a KSON document must be either an *array* of\nobjects or an *object*. A plain value or an *array* of plain values\ncannot be serialized.\n\n\nCodecs\n------\n\nDecoders are executed in the order of their definition in the meta field.\nThe decoder is passed the value to decode as the first argument and the\nintermediate data object as the second. The intermediate object will have\nthe values of all previous fields decoded and applied.\n\n\nIncluded codecs:\n\n enum:a:b:c:d \"a\" -> 0, \"b\" -> 1, ...\n prefix:egg \"eggbacon\" -> \"bacon\"\n suffix:bacon \"eggsausagebacon\" -> \"eggsausage\"\n bool true -> 1, false -> 0\n date new Date() -> 1364938727390\n int36 1364938727390 -> \"hf1lcnka\"\n\n\nCodec chaining\n\n prefix:egg|suffix:bacon \"eggsausagebacon\" -> \"sausage\"\n date|int36 new Date() -> \"hf1lcnka\"\n\n\nCustom codecs are registered using factory functions in the following manner.\n\n KSON.coders[\"my_coder_id\"] = function(args) {\n // args is a string array from a schemas meta field\n // enum:a:b:c:d -> args == [\"a\", \"b\", \"c\", \"d\"]\n\n return function (val, encode) {\n // The actual encoding/decoding function\n return encode ? encode_op(val) : decode_op(val);\n }\n }\n\nSchema Validation\n-----------------\n\nThe python library validates schemas and codec definitions, the javascript\nlibrary does not. Invalid schema definition loaded with the javascript\nlibrary may parse or stringify bad data without any throwing any errors.\n\nCommon errors include:\n - Loading a schema before the custom codecs it uses have been registered.\n - Loading a schema before the subschemas on which it depends have been\n loaded. Note that schemas are loaded in the order they appear in a file,\n so dependent schmas schould come after those they depend uppon.\n - Circularly dependent schmas (including schemas which depend on \n themselves) are possible by using a stub schema, which only specifies\n an id and no fields. This can be replaced by the propper schema with\n the same id, after its dependencies have been loaded.\n - Loading a json encoded schema. The argument of the KSON.addSchema\n function may be either a KSON encoded schema or schemas, an already\n decoded schema or an array of schemas. It is however fairly simple to\n load json encoded schemas: KSON.addSchema(JSON.parse(raw_json_schemas));\n\nThe python library will warn about these and other issues, so use it to\n\n\nInstallation\n------------\n\n $ pip install kson\n\nAutomatic schema detection:\n \n $ kson --auto-detect data.json --id schema_id\n\n\nDevelopment\n-----------\n\n $ git clone git@bitbucket.org:mbarkhau/kson.git\n $ npm install uglify-js -g\n $ npm install benchmark microtime\n\n $ pip install py.test\n\n $ make test\n $ make bench\n $ make minify", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://bitbucket.org/mbarkhau/kson/", "keywords": "kson json parser javascript schema", "license": "BSD License", "maintainer": null, "maintainer_email": null, "name": "kson", "package_url": "https://pypi.org/project/kson/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/kson/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://bitbucket.org/mbarkhau/kson/" }, "release_url": "https://pypi.org/project/kson/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "Keystripped Schemafied Object Notation", "version": "0.1.0" }, "last_serial": 772303, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "32ee175cbe9d746ee48bdcdae8283b99", "sha256": "a36eccd8958f0cd58a0ad1a2ca4de335177b152c695406a66e386bf57b54e82d" }, "downloads": -1, "filename": "kson-0.1.0.tar.gz", "has_sig": false, "md5_digest": "32ee175cbe9d746ee48bdcdae8283b99", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9395, "upload_time": "2013-04-28T00:13:14", "url": "https://files.pythonhosted.org/packages/8a/3c/80bbeecf16c734c0bb117967d6cafaf449a5be8d03f91424657263b02acc/kson-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "32ee175cbe9d746ee48bdcdae8283b99", "sha256": "a36eccd8958f0cd58a0ad1a2ca4de335177b152c695406a66e386bf57b54e82d" }, "downloads": -1, "filename": "kson-0.1.0.tar.gz", "has_sig": false, "md5_digest": "32ee175cbe9d746ee48bdcdae8283b99", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9395, "upload_time": "2013-04-28T00:13:14", "url": "https://files.pythonhosted.org/packages/8a/3c/80bbeecf16c734c0bb117967d6cafaf449a5be8d03f91424657263b02acc/kson-0.1.0.tar.gz" } ] }