sg-schema-casting

1.3.1 • Public • Published

schema-casting Build Status

Tiny tool aimed to type cast raw data based on provided json schema.

Installation

npm i schema-casting

Usage

const sc = require('schema-casting');
 
const schema = {
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "a": { "required": true, "type": "integer" },
    "b": { "required": true, "type": "boolean" },
    "c": { "required": true, "type": "number" },
    "d": {
      "required": true,
      "type": "object",
      "properties": {
        "e": {
          "required": true,
          "type": "number",
        }
      }
    }
  },
  "required": true,
  "additionalProperties": false
};
 
const input = {
  a: '1',
  b: 'true',
  c: '2.3',
  d: { e: '4.56' },
};
 
const output = sc(schema, input);
console.log(output);
// { a: 1, b: true, c: 2.3, d: { e: 4.56 } }

License

MIT

/sg-schema-casting/

    Package Sidebar

    Install

    npm i sg-schema-casting

    Weekly Downloads

    6

    Version

    1.3.1

    License

    MIT

    Unpacked Size

    21.7 kB

    Total Files

    13

    Last publish

    Collaborators

    • hwaranglee
    • sngsng
    • piorio0919
    • kspark