Skip to content

savi2w/yup-of-json

Repository files navigation

Yup of JSON

Convert JSON to a yup schema

Usage

import parse from "@savi2w/yup-of-json";

Example

  • JSON Schema
{
  "addresses": {
    "raw": "Kukuroo Mountain"
  },
  "age": 14,
  "github": "https://github.com/savi2w",
  "hunter": true,
  "name": "Killua Zoldyck",
  "role": null,
  "tags": [
    {
      "label": "cute"
    }
  ]
}
  • Result
yup
  .object()
  .shape({
    addresses: yup
      .object()
      .shape({ raw: yup.string().required() })
      .noUnknown()
      .required(),
    age: yup.number().required(),
    github: yup.string().required(),
    hunter: yup.boolean().nullable(),
    name: yup.string().required(),
    role: yup.mixed().nullable(),
    tags: yup
      .array()
      .of(
        yup
          .object()
          .shape({ label: yup.string().required() })
          .noUnknown()
          .required()
      )
      .defined(),
  })
  .noUnknown()
  .required();

License

This project is distributed under the MIT license

About

Convert JSON to a yup schema

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published