Converts a Validation value to a JavaScript object that may be stored as a JSON value.
This API is still experimental, so it may change or be removed in future versions. You should not rely on it for production applications.
type JSONSerialisation = {
"@@type": String,
"@@tag": String,
"@@value": Object Any
}
Variant . () => JSONSerialisation
Converts a Validation value to a JavaScript object that may be stored as a JSON value.
See the docs for adt/union/derivations/serialization
for more details.
const { Success, Failure } = require('folktale/validation');
Success('a').toJSON();
// ==> { '@@type': 'folktale:Validation', '@@tag': 'Success', '@@value': { value: 'a' }}
Failure('a').toJSON();
// ==> { '@@type': 'folktale:Validation', '@@tag': 'Failure', '@@value': { value: 'a' }}
function() {
return {
[typeJsonKey]: typeName,
[tagJsonKey]: tagName,
[valueJsonKey]: mapValues(this, serializeValue)
};
}