{
  "author": {
    "name": "Kevin Malakoff",
    "url": "https://github.com/kmalakoff"
  },
  "name": "json-serialize",
  "description": "JSON-Serialize.js provides conventions and helpers to manage serialization and deserialization of instances to/from JSON.",
  "keywords": [
    "json-serialize",
    "json-serializejs",
    "json",
    "util",
    "server",
    "client"
  ],
  "url": "http://kmalakoff.github.com/json-serialize/",
  "homepage": "http://kmalakoff.github.com/json-serialize/",
  "repository": {
    "type": "git",
    "url": "http://github.com/kmalakoff/json-serialize.git"
  },
  "main": "json-serialize.js",
  "version": "1.1.2",
  "readme": "JSON-Serialize.js provides conventions and helpers to manage serialization and deserialization of instances to/from JSON.\n\n#Download Latest (1.1.2):\n\nPlease see the [release notes](https://github.com/kmalakoff/json-serialize/blob/master/RELEASE_NOTES.md) for upgrade pointers.\n\n* [Development version](https://raw.github.com/kmalakoff/json-serialize/1.1.2/json-serialize.js)\n* [Production version](https://raw.github.com/kmalakoff/json-serialize/1.1.2/json-serialize.min.js)\n\n###Module Loading\n\nJSON-Serialize.js is compatible with RequireJS, CommonJS, Brunch and AMD module loading. Module names:\n\n* 'json-serialize' - json-serialize.js.\n\nExamples\n--------\n\n1) JSON-Serialize natively supports nested Date serialization so this \"just works\":\n\n```javascript\nvar embedded_date_objects = [\n  new Date(),\n  {to: new Date, from: new Date},\n  [1, new Date]\n];\n\nvar json = JSON.serialize(embedded_date_objects);\nvar deserialized_embedded_date_objects = JSON.deserialize(json);\n\nequal(_.isEqual(embedded_date_objects, deserialized_embedded_date_objects), true, 'the nested dates were deserialized automatically')\n```\n\nPretty cool, eh?\n\n2) Creating custom serialization for one of your classes.\n\n```coffeescript\nclass SomeClass\n  constructor: (int_value, string_value, date_value) ->\n    this.int_value = int_value;\n    this.string_value = string_value;\n    this.date_value = date_value;\n\n  toJSON: ->\n    return {\n      _type:'SomeClass',\n      int_value:this.int_value,\n      string_value:this.string_value,\n      date_value:JSON.serialize(this.date_value)\n    }\n\n  @fromJSON: (json) ->    # note: this is a class method\n    if (json._type!='SomeClass') return null;\n    return new SomeClass(json.int_value, json.string_value, JSON.deserialize(json.date_value));\n```\n\nNow you can automatically serialize and deserialize it:\n\n```coffeescript\ninstance = new SomeClass(1, 'two', new Date());\njson = JSON.serialize(instance)   # this calls the toJSON function on the instance\n\ninstance2 = JSON.deserialize(json)   # this calls the fromJSON function on the class (you need to make sure the constructor can be found)\n```\n\n# Conventions\n\nUses the following configurable conventions:\n\n1. use a '_type\" field in the json that you serialize\n2. for serializing, implement a toJSON function as an **instance** method.\n3. for deserializing, implement a fromJSON deserialization factory function as an **class** method. This doesn't need to be a class function but can be any function as long as it can be found (see JSON.deserialize.NAMESPACE_ROOTS).\n\n# Options\n\n* JSON.deserialize.TYPE_FIELD\n\nYou can globally choose the type field used when deserializing an instance from JSON.\n\nFor example, if you use couchdb, you could use a 'type' field convention:\n\n```coffeescript\nJSON.deserialize.TYPE_FIELD = 'type'\n```\n\n* JSON.deserialize.NAMESPACE_ROOTS\n\nIf you don't want to pollute the global namespace with your deserialization factory functions, you can put them in any sort of nested namespaces. Just register your namespace roots like:\n\n```coffeescript\nJSON.deserialize.NAMESPACE_ROOTS.push(window.my_classes)\n```\n\nBuilding, Running and Testing the library\n-----------------------\n\n###Installing:\n\n1. install node.js: http://nodejs.org\n2. install node packages: 'npm install'\n\n###Commands:\n\nLook at: https://github.com/kmalakoff/easy-bake",
  "readmeFilename": "README.md",
  "bugs": {
    "url": "https://github.com/kmalakoff/json-serialize/issues"
  },
  "_id": "json-serialize@1.1.2",
  "_from": "json-serialize@"
}
