Skip to content

Instantly share code, notes, and snippets.

@dcleao
Last active November 15, 2015 18:04
Show Gist options
  • Save dcleao/dbe9cd3795d5db55a4d5 to your computer and use it in GitHub Desktop.
Save dcleao/dbe9cd3795d5db55a4d5 to your computer and use it in GitHub Desktop.
JSON-Type
// 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: ""}
})
@dcleao
Copy link
Author

dcleao commented Nov 15, 2015

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 and undef), 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:

var foo : string = "bar";

@dcleao
Copy link
Author

dcleao commented Nov 15, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment