Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
json-serialize
Advanced tools
JSON-Serialize.js provides conventions and helpers to manage serialization and deserialization of instances to/from JSON.
JSON-Serialize.js provides conventions and helpers to manage serialization and deserialization of instances to/from JSON.
#Download Latest (1.1.3):
Please see the release notes for upgrade pointers.
###Module Loading
JSON-Serialize.js is compatible with RequireJS, CommonJS, Brunch and AMD module loading. Module names:
var embedded_date_objects = [
new Date(),
{to: new Date, from: new Date},
[1, new Date]
];
var json = JSON.serialize(embedded_date_objects);
var deserialized_embedded_date_objects = JSON.deserialize(json);
equal(_.isEqual(embedded_date_objects, deserialized_embedded_date_objects), true, 'the nested dates were deserialized automatically')
Pretty cool, eh?
class SomeClass
constructor: (int_value, string_value, date_value) ->
this.int_value = int_value;
this.string_value = string_value;
this.date_value = date_value;
toJSON: ->
return {
_type:'SomeClass',
int_value:this.int_value,
string_value:this.string_value,
date_value:JSON.serialize(this.date_value)
}
@fromJSON: (json) -> # note: this is a class method
if (json._type!='SomeClass') return null;
return new SomeClass(json.int_value, json.string_value, JSON.deserialize(json.date_value));
Now you can automatically serialize and deserialize it:
instance = new SomeClass(1, 'two', new Date());
json = JSON.serialize(instance) # this calls the toJSON function on the instance
instance2 = JSON.deserialize(json) # this calls the fromJSON function on the class (you need to make sure the constructor can be found)
Uses the following configurable conventions:
You can globally choose the type field used when deserializing an instance from JSON.
For example, if you use couchdb, you could use a 'type' field convention:
JSON.deserialize.TYPE_FIELD = 'type'
If 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:
JSON.deserialize.NAMESPACE_ROOTS.push(window.my_classes)
###Installing:
###Commands:
FAQs
JSON-Serialize.js provides conventions and helpers to manage serialization and deserialization of instances to/from JSON.
The npm package json-serialize receives a total of 79 weekly downloads. As such, json-serialize popularity was classified as not popular.
We found that json-serialize demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.