toJSON

Converts a Validation value to a JavaScript object that may be stored as a JSON value.

This feature is experimental!

This API is still experimental, so it may change or be removed in future versions. You should not rely on it for production applications.

Signature

toJSON()
type JSONSerialisation = {
  "@@type":  String,
  "@@tag":   String,
  "@@value": Object Any
}

Variant . () => JSONSerialisation

Documentation

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.

Example:

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' }}

Properties

Source Code

function() {
    return { 
      [typeJsonKey]:  typeName, 
      [tagJsonKey]:   tagName, 
      [valueJsonKey]: mapValues(this, serializeValue) 
    };
  }
Stability
experimental
Licence
MIT
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • @boris-marinov
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)