{"id":16531290,"url":"https://github.com/bjrmatos/json-schema-sugar","last_synced_at":"2025-08-20T19:04:36.101Z","repository":{"id":57285217,"uuid":"70955433","full_name":"bjrmatos/json-schema-sugar","owner":"bjrmatos","description":"Create a JSON Schema without the pain of writing it :icecream:","archived":false,"fork":false,"pushed_at":"2017-01-29T18:24:07.000Z","size":73,"stargazers_count":20,"open_issues_count":1,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-07-30T05:37:17.691Z","etag":null,"topics":["json-schema","json-schema-sugar","schema-objects"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bjrmatos.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-15T00:05:01.000Z","updated_at":"2024-01-19T09:17:27.000Z","dependencies_parsed_at":"2022-09-17T13:03:55.811Z","dependency_job_id":null,"html_url":"https://github.com/bjrmatos/json-schema-sugar","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/bjrmatos/json-schema-sugar","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjrmatos%2Fjson-schema-sugar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjrmatos%2Fjson-schema-sugar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjrmatos%2Fjson-schema-sugar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjrmatos%2Fjson-schema-sugar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bjrmatos","download_url":"https://codeload.github.com/bjrmatos/json-schema-sugar/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjrmatos%2Fjson-schema-sugar/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268859123,"owners_count":24318874,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-05T02:00:12.334Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json-schema","json-schema-sugar","schema-objects"],"created_at":"2024-10-11T18:08:23.697Z","updated_at":"2025-08-20T19:04:36.045Z","avatar_url":"https://github.com/bjrmatos.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"json-schema-sugar\n=================\n\n[![NPM Version](http://img.shields.io/npm/v/json-schema-sugar.svg?style=flat-square)](https://npmjs.com/package/json-schema-sugar)[![License](http://img.shields.io/npm/l/json-schema-sugar.svg?style=flat-square)](http://opensource.org/licenses/MIT)[![Build Status](https://travis-ci.org/bjrmatos/json-schema-sugar.png?branch=master)](https://travis-ci.org/bjrmatos/json-schema-sugar)\n\n\u003e **Create a JSON Schema without the pain of writing it**\n\nThis module let you write [JSON Schemas v4](http://json-schema.org/) in a \"sugar\" way (using a chainable API).\nThe API and style is ~~stolen~~ heavily inspired by [Joi](https://github.com/hapijs/joi) and [Yup](https://github.com/jquense/yup).\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n\n- [Usage](#usage)\n- [API](#api)\n  - [`sugar`](#sugar)\n  - [mixed](#mixed)\n    - [`mixed.clone(): Schema`](#mixedclone-schema)\n    - [`mixed.title(title: string): Schema`](#mixedtitletitle-string-schema)\n    - [`mixed.description(description: string): Schema`](#mixeddescriptiondescription-string-schema)\n    - [`mixed.default(default: any): Schema`](#mixeddefaultdefault-any-schema)\n    - [`mixed.meta(field: string | object, value: ?any): Schema` Alias: `extra`](#mixedmetafield-string--object-value-any-schema-alias-extra)\n    - [`mixed.enum(values: Array\u003cany\u003e): Schema`](#mixedenumvalues-arrayany-schema)\n    - [`mixed.required(): Schema`](#mixedrequired-schema)\n    - [`mixed.requiredWhen(dependantProp: string | Array\u003cstring\u003e): Schema`](#mixedrequiredwhendependantprop-string--arraystring-schema)\n    - [`mixed.when(dependantProp: string | Array\u003cstring\u003e): Schema`](#mixedwhendependantprop-string--arraystring-schema)\n    - [`mixed.definitions(definitions: object): Schema`](#mixeddefinitionsdefinitions-object-schema)\n    - [`mixed.allOf(schemas: Array\u003cSchema\u003e): Schema`](#mixedallofschemas-arrayschema-schema)\n    - [`mixed.anyOf(schemas: Array\u003cSchema\u003e): Schema`](#mixedanyofschemas-arrayschema-schema)\n    - [`mixed.oneOf(schemas: Array\u003cSchema\u003e): Schema`](#mixedoneofschemas-arrayschema-schema)\n    - [`mixed.not(schema: Schema): Schema`](#mixednotschema-schema-schema)\n    - [`mixed.noType(): Schema`](#mixednotype-schema)\n    - [`mixed.canBe(type: Schema | Array\u003cSchema\u003e): Schema`](#mixedcanbetype-schema--arrayschema-schema)\n    - [`mixed.ref(refUri: string): Schema`](#mixedrefrefuri-string-schema)\n    - [`mixed.generate(options: ?object): string`](#mixedgenerateoptions-object-string)\n  - [nullable](#nullable)\n  - [boolean](#boolean)\n  - [number](#number)\n    - [`number.integer(): Schema`](#numberinteger-schema)\n    - [`number.multipleOf(value: number): Schema`](#numbermultipleofvalue-number-schema)\n    - [`number.minimum(value: number): Schema`](#numberminimumvalue-number-schema)\n    - [`number.maximum(value: number): Schema`](#numbermaximumvalue-number-schema)\n    - [`number.exclusiveMinimum(value: boolean): Schema`](#numberexclusiveminimumvalue-boolean-schema)\n    - [`number.exclusiveMaximum(value: boolean): Schema`](#numberexclusivemaximumvalue-boolean-schema)\n  - [string](#string)\n    - [`string.minLength(value: number): Schema`](#stringminlengthvalue-number-schema)\n    - [`string.maxLength(value: number): Schema`](#stringmaxlengthvalue-number-schema)\n    - [`string.pattern(pattern: string | RegExp): Schema`](#stringpatternpattern-string--regexp-schema)\n    - [`string.format(format: string): Schema`](#stringformatformat-string-schema)\n  - [object](#object)\n    - [`object.keys(properties: object): Schema`](#objectkeysproperties-object-schema)\n    - [`object.additionalProperties(value: boolean | Schema): Schema`](#objectadditionalpropertiesvalue-boolean--schema-schema)\n    - [`object.patternProperties(value: object): Schema`](#objectpatternpropertiesvalue-object-schema)\n    - [`object.minProperties(value: number): Schema`](#objectminpropertiesvalue-number-schema)\n    - [`object.maxProperties(value: number): Schema`](#objectmaxpropertiesvalue-number-schema)\n  - [array](#array)\n    - [`array.items(items: object | Schema | Array\u003cSchema\u003e): Schema`](#arrayitemsitems-object--schema--arrayschema-schema)\n    - [`array.additionalItems(value: boolean): Schema`](#arrayadditionalitemsvalue-boolean-schema)\n    - [`array.minItems(value: number): Schema`](#arrayminitemsvalue-number-schema)\n    - [`array.maxItems(value: number): Schema`](#arraymaxitemsvalue-number-schema)\n    - [`array.uniqueItems(value: boolean): Schema`](#arrayuniqueitemsvalue-boolean-schema)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Usage\n\nDefine and create schema objects. Schema objects are immutable, so each call of a method returns a _new_ schema object.\n\n```js\nvar sugar = require('json-schema-sugar');\n\nvar schema = sugar.object().keys({\n  name: sugar.string().required(),\n  age: sugar.number().integer().required(),\n  email: sugar.string(),\n  website: sugar.string()\n});\n\nvar jsonSchema = schema.generate({\n  name: 'jimmy',\n  age: 24\n});\n\nconsole.log(jsonSchema);\n```\n\nOutput:\n\n```js\n{\n  type: 'object',\n  properties: {\n    name: {\n      type: 'string'\n    },\n    age: {\n      type: 'integer'\n    },\n    email: {\n      type: 'string'\n    },\n    website: {\n      type: 'string'\n    }\n  },\n  required: ['name', 'age']\n}\n```\n\n## API\n\n### `sugar`\n\nThe module export.\n\n```js\nvar sugar = require('json-schema-sugar');\n\nsugar.mixed // also aliased as sugar.any\nsugar.nullable\nsugar.string\nsugar.number\nsugar.boolean\nsugar.object\nsugar.array\n```\n\n### mixed\n\nCreates a schema that matches a general type. All types inherit from this base type\n\n```js\nvar schema = sugar.mixed();\nschema.generate();\n// =\u003e {}\n```\n\n#### `mixed.clone(): Schema`\n\nCreates a deep copy of the schema. Clone is used internally to return a new schema with every schema state change (making schema instances inmutable).\n\n#### `mixed.title(title: string): Schema`\n\nAdds a title in the schema.\n\n#### `mixed.description(description: string): Schema`\n\nAdds a description in the schema.\n\n#### `mixed.default(default: any): Schema`\n\nAdds a default value in the schema.\n\n#### `mixed.meta(field: string | object, value: ?any): Schema` Alias: `extra`\n\nAdds custom fields to the schema, multiple calls to `.meta` will accumulate data with previous calls.\n\nWith field:\n\n```js\nvar schema = sugar.object().keys({\n  name: sugar.string().required().meta('example', 'Bob').meta('isMain', true),\n});\n\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'object',\n  properties: {\n    name: {\n      type: 'string',\n      example: 'Bob',\n      isMain: true\n    }\n  }\n}\n```\n\nWith an Object:\n\n```js\nvar schema = sugar.object().keys({\n  name: sugar.string().required().meta({ example: 'Bob', isMain: true }),\n});\n\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'object',\n  properties: {\n    name: {\n      type: 'string',\n      example: 'Bob',\n      isMain: true\n    }\n  }\n}\n```\n\n#### `mixed.enum(values: Array\u003cany\u003e): Schema`\n\nRestricts a value in the schema to a fixed set of values.\n\n#### `mixed.required(): Schema`\n\nWhen used inside an object schema specifies that a property is required.\n\n```js\nvar schema = sugar.object().keys({\n  name: sugar().string().required(),\n  email: sugar().string().required(),\n  address: sugar.string()\n});\n\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'object',\n  properties: {\n    name: {\n      type: 'string'\n    },\n    email: {\n      type: 'string'\n    },\n    address: {\n      type: 'string'\n    }\n  },\n  required: ['name', 'email']\n}\n```\n\n#### `mixed.requiredWhen(dependantProp: string | Array\u003cstring\u003e): Schema`\n\nWhen used inside an object schema specifies that a property must be present (required)\nwhen another property/properties are present, making a `property dependency`.\n`dependantProp` can be an array of strings, or multiple strings can be passed as individual arguments.\n\n```js\nvar schema = sugar.object().keys({\n  name: sugar.string().required(),\n  creditCard: sugar.number(),\n  billingAddress: sugar.string().requiredWhen('creditCard', 'name'),\n  billingDistrict: sugar.string().requiredWhen('creditCard')\n});\n\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'object',\n  properties: {\n    name: {\n      type: 'string'\n    },\n    creditCard: {\n      type: 'number'\n    },\n    billingAddress: {\n      type: 'string'\n    },\n    billingDistrict: {\n      type: 'string'\n    }\n  },\n  required: ['name'],\n  dependencies: {\n    creditCard: ['billingAddress', 'billingDistrict'],\n    name: ['billingAddress']\n  }\n}\n```\n\n#### `mixed.when(dependantProp: string | Array\u003cstring\u003e): Schema`\n\nWhen used inside an object schema specifies that when a property is present the schema\nshould be different, making a `schema dependency`.\n`dependantProp` can be an array of strings, or multiple strings can be passed as individual arguments.\n\n```js\nvar schema = sugar.object().keys({\n  name: sugar.string(),\n  creditCard: sugar.number(),\n  billingAddress: sugar.mixed().when('creditCard', sugar.string().required())\n});\n\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'object',\n  properties: {\n    name: {\n      type: 'string'\n    },\n    creditCard: {\n      type: 'number'\n    }\n  },\n  dependencies: {\n    creditCard: {\n      properties: {\n        billingAddress: {\n          type: 'string'\n        }\n      },\n      required: ['billingAddress']\n    }\n  }\n}\n```\n\n#### `mixed.definitions(definitions: object): Schema`\n\nAdds definitions to the schema, definitions are standardized placeholder in which you can define inline subschemas to be used in a schema.\n\n```js\nvar schema = sugar.object().keys({\n  billingAddress: sugar.any().ref('#/definitions/address')\n}).definitions({\n  address: sugar.object().keys({\n    streetAddress: sugar.string().required(),\n    city: sugar.string().required(),\n    state: sugar.string().required()\n  })\n});\n\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'object',\n  properties: {\n    billingAddress: {\n      $ref: '#/definitions/address'\n    }\n  },\n  definitions: {\n    address: {\n      type: 'object',\n      properties: {\n        streetAddress: {\n          type: 'string'\n        },\n        city: {\n          type: 'string'\n        },\n        state: {\n          type: 'string'\n        }\n      },\n      required: ['streetAddress', 'city', 'state']\n    }\n  }\n}\n```\n\n#### `mixed.allOf(schemas: Array\u003cSchema\u003e): Schema`\n\nAdds a restriction that the given data must be valid against all of the given subschemas.\n\n```js\nvar schema = sugar.mixed().allOf([\n  sugar.string(),\n  sugar.string().minLength(2),\n  sugar.string().maxLength(5)\n]);\n```\n\nOutput:\n\n```js\n{\n  allOf: [{\n    type: 'string'\n  }, {\n    minLength: 2\n  }, {\n    maxLength: 5\n  }]\n}\n```\n\n#### `mixed.anyOf(schemas: Array\u003cSchema\u003e): Schema`\n\nAdds a restriction that the given data must be valid against any (one or more) of the given subschemas.\n\n```js\nvar schema = sugar.mixed().anyOf([\n  sugar.string().maxLength(5),\n  sugar.number().minimum(0)\n]);\n```\n\nOutput:\n\n```js\n{\n  anyOf: [{\n    type: 'string',\n    maxLength: 5\n  }, {\n    type: 'number',\n    minimum: 0\n  }]\n}\n```\n\n#### `mixed.oneOf(schemas: Array\u003cSchema\u003e): Schema`\n\nAdds a restriction that the given data must be valid against exactly one of the given subschemas.\n\n```js\nvar schema = sugar.mixed().oneOf([\n  sugar.number().multipleOf(3),\n  sugar.number().multipleOf(5)\n]);\n```\n\nOutput:\n\n```js\n{\n  oneOf: [{\n    type: 'number',\n    multipleOf: 3\n  }, {\n    type: 'number',\n    multipleOf: 5\n  }]\n}\n```\n\n#### `mixed.not(schema: Schema): Schema`\n\nDeclares that a instance validates if it doesn’t validate against the given subschema.\n\n```js\nvar schema = sugar.mixed().not(sugar.string());\n```\n\nOutput:\n\n```js\n{\n  not: {\n    type: 'string'\n  }\n}\n```\n\n#### `mixed.noType(): Schema`\n\nDeclares that a schema should not include the `type` property in the output.\n\n```js\nvar schema = sugar.number().multipleOf(5).noType();\n```\n\nOutput:\n\n```js\n{\n  multipleOf: 5\n}\n```\n\n#### `mixed.canBe(type: Schema | Array\u003cSchema\u003e): Schema`\n\nSpecify multiple types for a schema. `type` can be an array of schemas, or multiple schemas can be passed as individual arguments.\n**This method is only available to `mixed` schemas (schemas created directly with `sugar.mixed()`)**\n\n```js\nvar schema = sugar.mixed().canBe(sugar.string(), sugar.number());\nschema.generate();\n// =\u003e { type: ['string', 'number'] }\n```\n\n#### `mixed.ref(refUri: string): Schema`\n\nCreates a reference to a schema located in `refUri`. **This method is only available to `mixed` schemas (schemas created directly with `sugar.mixed()`)**\n\n```js\nvar schema = sugar.object().keys({\n  billingAddress: sugar.any().ref('#/definitions/address'),\n  shippingAddress: sugar.any().allOf([\n    sugar.any().ref('#/definitions/address'),\n    sugar.object().keys({\n      type: sugar.any().enum(['residential', 'business']).required()\n    })\n  ])\n}).definitions({\n  address: sugar.object().keys({\n    streetAddress: sugar.string().required(),\n    city: sugar.string().required(),\n    state: sugar.string().required()\n  })\n});\n```\n\nOutput:\n\n```js\n{\n  type: 'object',\n  properties: {\n    billingAddress: {\n      $ref: '#/definitions/address'\n    },\n    shippingAddress: {\n      allOf: [{\n        $ref: '#/definitions/address'\n      }, {\n        properties: {\n          type: {\n            enum: ['residential', 'business']\n          }\n        },\n        required: ['type']\n      }]\n    }\n  },\n  definitions: {\n    address: {\n      type: 'object',\n      properties: {\n        streetAddress: {\n          type: 'string'\n        },\n        city: {\n          type: 'string'\n        },\n        state: {\n          type: 'string'\n        }\n      },\n      required: ['streetAddress', 'city', 'state']\n    }\n  }\n}\n```\n\n#### `mixed.generate(options: ?object): string`\n\nGenerates a `JSON Schema` based on the constructed schema.\n\nThe `options` (optional) argument is an object hash and can contain the following properties:\n\n```js\noptions = {\n  obj: boolean = false,\n  removeType: boolean = false,\n  space: ?number = undefined,\n  $schema: ?string = undefined,\n  id: ?string = undefined\n};\n```\n\n- `obj`: return the `JSON Schema` as object instead of string.\n- `removeType`: don't include the `type` property in the `JSON Schema`.\n- `space`: Specifies the `space` option for `JSON.stringify`, adding the ability to return the json string with white space.\n- `$schema`: Specifies a custom `$schema` entry in the `JSON Schema`.\n- `id`: Specifies an `id` entry in the `JSON Schema`.\n\n### nullable\n\nCreates a schema that matches a `null` type. Supports all the same methods as [`mixed`](#mixed).\n\n```js\nvar schema = sugar.nullable();\nschema.generate();\n// =\u003e { type: 'null' }\n```\n\n### boolean\n\nCreates a schema that matches a `boolean` type. Supports all the same methods as [`mixed`](#mixed).\n\n```js\nvar schema = sugar.boolean();\nschema.generate();\n// =\u003e { type: 'boolean' }\n```\n\n### number\n\nCreates a schema that matches a `number` type. Supports all the same methods as [`mixed`](#mixed).\n\n```js\nvar schema = sugar.number();\nschema.generate();\n// =\u003e { type: 'number' }\n```\n\n#### `number.integer(): Schema`\n\nDefines that the schema should be an `integer`.\n\n```js\nvar schema = sugar.number().integer();\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'integer'\n}\n```\n\n#### `number.multipleOf(value: number): Schema`\n\nDefines that the schema should be multiple of `value`.\n\n```js\nvar schema = sugar.number().multipleOf(3);\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'number',\n  multipleOf: 3\n}\n```\n\n#### `number.minimum(value: number): Schema`\n\nDefines that the schema should be a minimum numeric `value`.\n\n```js\nvar schema = sugar.number().minimum(5);\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'number',\n  minimum: 5\n}\n```\n\n#### `number.maximum(value: number): Schema`\n\nDefines that the schema should be a maximum numeric `value`.\n\n```js\nvar schema = sugar.number().maximum(10);\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'number',\n  maximum: 10\n}\n```\n\n#### `number.exclusiveMinimum(value: boolean): Schema`\n\nWhen `value` is `true`, it indicates that the range excludes the `minimum` value,\ni.e., `x \u003e minx \u003e min`. When `false` (or not included), it indicates that the range includes the `minimum` value, i.e., `x ≥ minx ≥ min`.\n\n```js\nvar schema = sugar.number().minimum(5).exclusiveMinimum(true);\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'number',\n  minimum: 5,\n  exclusiveMinimum: true\n}\n```\n\n#### `number.exclusiveMaximum(value: boolean): Schema`\n\nWhen `value` is `true`, it indicates that the range excludes the `maximum` value,\ni.e., `x \u003c maxx \u003cmax`. When `false` (or not included), it indicates that the range includes the `maximum` value, i.e., `x ≤ maxx ≤ max`.\n\n```js\nvar schema = sugar.number().maximum(10).exclusiveMaximum(true);\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'number',\n  maximum: 10,\n  exclusiveMaximum: true\n}\n```\n\n### string\n\nCreates a schema that matches a `string` type. Supports all the same methods as [`mixed`](#mixed).\n\n```js\nvar schema = sugar.string();\nschema.generate();\n// =\u003e { type: 'string' }\n```\n\n#### `string.minLength(value: number): Schema`\n\nDefines that a string should have a minimum length of `value`.\n\n```js\nvar schema = sugar.string().minLength(2);\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'string',\n  minLength: 2\n}\n```\n\n#### `string.maxLength(value: number): Schema`\n\nDefines that a string should have a maximum length of `value`.\n\n```js\nvar schema = sugar.string().maxLength(8);\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'string',\n  maxLength: 8\n}\n```\n\n#### `string.pattern(pattern: string | RegExp): Schema`\n\nDefines that a string should satisfies a `pattern`.\n\n```js\nvar schema = sugar.string().pattern(/abc/);\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'string',\n  pattern: 'abc'\n}\n```\n\n#### `string.format(format: string): Schema`\n\nDefines a format for the string. `format` can be any standardized format like `date-time`, `email`, etc.\n\n```js\nvar schema = sugar.string().format('email');\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'string',\n  format: 'email'\n}\n```\n\n### object\n\nCreates a schema that matches a `object` type. Supports all the same methods as [`mixed`](#mixed).\n\n```js\nvar schema = sugar.object().keys({\n  name: sugar.string()\n});\n\nschema.generate();\n// =\u003e { type: 'object', properties: { name: { type: 'string' } } }\n```\n\n#### `object.keys(properties: object): Schema`\n\nDefines properties for the object. Each key in the `properties` hash object must have a `Schema` as value.\n\n```js\nvar schema = sugar.object().keys({\n  foo: sugar.boolean(),\n  value: sugar.number(),\n  address: sugar.string(),\n  unknown: sugar.nullable()\n});\n\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'object',\n  properties: {\n    foo: {\n      type: 'boolean'\n    },\n    value: {\n      type: 'number'\n    },\n    address: {\n      type: 'string'\n    },\n    unknown: {\n      type: 'null'\n    }\n  }\n}\n```\n\n#### `object.additionalProperties(value: boolean | Schema): Schema`\n\nDefines if an object can have additional properties or not.\nIf `value` is a `Schema` then all additional properties must be valid against the given schema.\n\n```js\nvar schema = sugar.object().keys({\n  foo: sugar.boolean(),\n  value: sugar.number(),\n  address: sugar.string(),\n  unknown: sugar.nullable()\n}).additionalProperties(sugar.string());\n\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'object',\n  properties: {\n    foo: {\n      type: 'boolean'\n    },\n    value: {\n      type: 'number'\n    },\n    address: {\n      type: 'string'\n    },\n    unknown: {\n      type: 'null'\n    }\n  },\n  additionalProperties: {\n    type: 'string'\n  }\n}\n```\n\n#### `object.patternProperties(value: object): Schema`\n\nDefines that if there is any property in an object that match a given pattern, that property must be valid against a schema.\n\nEach key in the `value` hash object must have a `Schema` as value.\n\n```js\nvar schema = sugar.object().keys({\n  foo: sugar.boolean(),\n  value: sugar.number(),\n  address: sugar.string(),\n  unknown: sugar.nullable()\n}).patternProperties({\n  '^S_': sugar.string(),\n  '^I_': sugar.number().integer()\n});\n\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'object',\n  properties: {\n    foo: {\n      type: 'boolean'\n    },\n    value: {\n      type: 'number'\n    },\n    address: {\n      type: 'string'\n    },\n    unknown: {\n      type: 'null'\n    }\n  },\n  patternProperties: {\n    '^S_': {\n      type: 'string'\n    },\n    '^I_': {\n      type: 'integer'\n    }\n  }\n}\n```\n\n#### `object.minProperties(value: number): Schema`\n\nDefines that an object should have a minimum number of properties.\n\n```js\nvar schema = sugar.object().keys({\n  foo: sugar.boolean(),\n  value: sugar.number(),\n  address: sugar.string(),\n  unknown: sugar.nullable()\n}).minProperties(2);\n\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'object',\n  properties: {\n    foo: {\n      type: 'boolean'\n    },\n    value: {\n      type: 'number'\n    },\n    address: {\n      type: 'string'\n    },\n    unknown: {\n      type: 'null'\n    }\n  },\n  minProperties: 2\n}\n```\n\n#### `object.maxProperties(value: number): Schema`\n\nDefines that an object should have a maximum number of properties.\n\n```js\nvar schema = sugar.object().keys({\n  foo: sugar.boolean(),\n  value: sugar.number(),\n  address: sugar.string(),\n  unknown: sugar.nullable()\n}).maxProperties(3);\n\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'object',\n  properties: {\n    foo: {\n      type: 'boolean'\n    },\n    value: {\n      type: 'number'\n    },\n    address: {\n      type: 'string'\n    },\n    unknown: {\n      type: 'null'\n    }\n  },\n  maxProperties: 3\n}\n```\n\n### array\n\nCreates a schema that matches a `array` type. Supports all the same methods as [`mixed`](#mixed).\n\n```js\nvar schema = sugar.array().items(sugar.number());\nschema.generate();\n// =\u003e { type: 'array', items: { type: 'number' } }\n```\n\n#### `array.items(items: object | Schema | Array\u003cSchema\u003e): Schema`\n\nWhen `items` is an `object` or `Schema` specifies that all items in an array must be valid against the given schema.\nWhen `items` is an `array` specifies that items in an array must be valid and appear in the same order of the given schemas (tuple validation).\n\n```js\nvar schema = sugar.array().items({\n  name: sugar.string(),\n  email: sugar.string()\n});\n\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'array',\n  items: {\n    type: 'object',\n    properties: {\n      name: {\n        type: 'string'\n      },\n      email: {\n        type: 'string'\n      }\n    }\n  }\n}\n```\n\nTuple example:\n\n```js\nvar schema = sugar.array().items([\n  sugar.number(),\n  sugar.string()\n]);\n\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'array',\n  items: [{\n    type: 'number'\n  }, {\n    type: 'string'\n  }]\n}\n```\n\n#### `array.additionalItems(value: boolean): Schema`\n\nDefines if an array can have additional items or not.\n\n```js\nvar schema = sugar.array().items([\n  sugar.string(),\n  sugar.number()\n]).additionalItems(false);\n\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'array',\n  items: [{\n    type: 'string'\n  }, {\n    type: 'number'\n  }],\n  additionalItems: false\n}\n```\n\n#### `array.minItems(value: number): Schema`\n\nDefines that an array should have a minimum number of items.\n\n```js\nvar schema = sugar.array().items({\n  value: sugar.number()\n}).minItems(2);\n\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'array',\n  items: {\n    type: 'object',\n    properties: {\n      value: {\n        type: 'number'\n      }\n    }\n  },\n  minItems: 2\n}\n```\n\n#### `array.maxItems(value: number): Schema`\n\nDefines that an array should have a maximum number of items.\n\n```js\nvar schema = sugar.array().items({\n  value: sugar.number()\n}).maxItems(2);\n\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'array',\n  items: {\n    type: 'object',\n    properties: {\n      value: {\n        type: 'number'\n      }\n    }\n  },\n  maxItems: 2\n}\n```\n\n#### `array.uniqueItems(value: boolean): Schema`\n\nDefines that items in an array should be unique.\n\n```js\nvar schema = sugar.array().items({\n  value: sugar.number()\n}).uniqueItems(true);\n\nschema.generate();\n```\n\nOutput:\n\n```js\n{\n  type: 'array',\n  items: {\n    type: 'object',\n    properties: {\n      value: {\n        type: 'number'\n      }\n    }\n  },\n  uniqueItems: true\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjrmatos%2Fjson-schema-sugar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbjrmatos%2Fjson-schema-sugar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjrmatos%2Fjson-schema-sugar/lists"}