Last active
November 15, 2015 18:04
-
-
Save dcleao/dbe9cd3795d5db55a4d5 to your computer and use it in GitHub Desktop.
JSON-Type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// custom JS function serialization/deserialization | |
// custom date, iso format | |
// special numbers: +/- Infinity | |
// undefined value | |
// --- | |
// A way to pass more data types through JSON. | |
// A way to be able to use JSONObject in Java. | |
// A way of de-serializing without additional metadata. | |
// A way that can be used with JSON.stringify and JSON.parse. | |
({ | |
foo: {":": "js/fun", "v": "function() {\n return \"foo\";\n}"}, | |
bar: {":": "date", "v": "2009-08-24T07:30:00Z"}, | |
guu: {":": "number", "v": "Infinity"}, | |
und: {":": "undef"}, | |
// TODO: AMD module class/factory? => async load... => not a good reviver... | |
// 2 passes? one for collecting dependencies other for resolving? | |
// Temptatively sync signature. Fails if some module is not already loaded. | |
// Async signature. | |
// new Guu(revivedSpec); | |
dah: {":": "amd:foo/bar/guu", customprop: "", otherprop: ""} | |
}) |
Some links about JSON + functions:
http://solutoire.com/2008/06/12/sending-javascript-functions-over-json/
https://github.com/josipk/json-plus
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Standardizes on a format for describing non-JSON types in JSON documents.
Apart from some possible standard types, like the ones in the example (
date
,number
andundef
), the idea is for the system to be extensible.No international registry for type names would exist. These would need to be known by the producers and consumers of the data.
Some of the data types may have native representations in some programming languages, and could be automatically converted to these upon deserialization. Unknown types would be left as JSON.
The main use case for this format is that of supporting component specifications that have functions as property values, without requiring metadata to be able to perform serialization and deserialization.
The ":" property name matches the syntax used in TypeScript (and others) for stating types of variables and parameters. Like in: