{"id":16306377,"url":"https://github.com/yanick/json-schema-shorthand","last_synced_at":"2025-10-25T14:30:51.152Z","repository":{"id":57285212,"uuid":"64510363","full_name":"yanick/json-schema-shorthand","owner":"yanick","description":"Shortcuts for json schema definition","archived":false,"fork":false,"pushed_at":"2023-06-01T16:13:02.000Z","size":155,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-18T02:07:31.520Z","etag":null,"topics":["json","json-schema"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yanick.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-07-29T21:03:46.000Z","updated_at":"2023-05-31T20:02:00.000Z","dependencies_parsed_at":"2024-06-20T23:28:03.810Z","dependency_job_id":null,"html_url":"https://github.com/yanick/json-schema-shorthand","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/yanick/json-schema-shorthand","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanick%2Fjson-schema-shorthand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanick%2Fjson-schema-shorthand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanick%2Fjson-schema-shorthand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanick%2Fjson-schema-shorthand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yanick","download_url":"https://codeload.github.com/yanick/json-schema-shorthand/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanick%2Fjson-schema-shorthand/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280832994,"owners_count":26398969,"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-10-24T02:00:06.418Z","response_time":73,"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","json-schema"],"created_at":"2024-10-10T21:10:28.927Z","updated_at":"2025-10-25T14:30:50.890Z","avatar_url":"https://github.com/yanick.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json-schema-shorthand\n\n[JSON Schema](http://json-schema.org/) is a useful beast,\nbut its schema definition can be a little bit more long-winded\nthan necessary. This module allows to use a few shortcuts that\nwill be expanded into their canonical form.\n\n## To install\n\n    npm install json-schema-shorthand\n\n## Typical use\n\n    import * as j from 'json-schema-shorthand';\n\n    let schema = j.object({\n        foo: 'number',\n        bar: array('string'),\n    });\n\n    // schema === {\n    //    type: 'object',\n    //    properties: {\n    //        foo: { type: 'number' },\n    //        bar: { type: 'array', items: { type: 'string' } }\n    //    }\n    // }\n\n## Compatibility with [json-schema-to-ts](https://www.npmjs.com/package/json-schema-to-ts)\n\n`json-schema-shorthand` can be used in conjecture with `json-schema-to-ts`.\nJust remember to `as const` your schemas to get the most precise types out\nof `FromSchema\u003c\u003e`.\n\n    const res = j.shorthand({\n        object: {\n            foo: \"number!\",\n        },\n        } as const\n    );\n\n    expectTypeOf(s).toMatchTypeOf\u003c{ foo: number; }\u003e();\n\n## Functions\n\n### `j.shorthand( schema )`\n\nTakes in a data structure\nand expands any shorthand (see next section) found in it. Note that because\n`json-schema-shorthand` is using\n[@yanick/updeep-remeda](https://www.npmjs.com/package/@yanick/updeep-remeda) internally, the returned schema\nis [frozen](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze).\n\nAlso the default export of `json-schema-shorthand`.\n\n    let schema = j.shorthand( { object: { foo: 'number' } });\n    // =\u003e { type: 'object', properties: { foo: { type: 'number' } } }\n\n### `j.number( description?, schema? )`\n\n    let schema = j.number( 'number of thingies', { maximum: 5 });\n    // =\u003e { type: 'number', description: 'number of thingies', maximum: 5 }\n\nExpands into a number type.\n\n### `j.integer( description?, schema? )`\n\n    let schema = j.integer({ maximum: 5 });\n    // =\u003e { type: 'integer', maximum: 5 }\n\nExpands into an integer type.\n\n### `j.string( description?, schema? )`\n\n    let schema = j.string({ maxLength: 5 });\n    // =\u003e { type: 'string', maxLength: 5 }\n\nExpands into a string type.\n\n### `j.array( itemsSchema, schema? )`\n\n    let schema = j.array('number', { maxItems: 5 });\n    // =\u003e { type: 'array', items: { type: 'number' }, maxItems: 5 }\n\nExpands into an array type.\n\n### `j.object( description?, properties, schema? )`\n\n    let schema = j.object({ foo: 'string!' }, { description: \"yadah\" });\n    // =\u003e { type: 'object',\n    //      properties: { foo: { type: 'string' } },\n    //      required: [ 'foo' ],\n    //      description: \"yadah\" }\n\nExpands into an object type.\n\n### `j.allOf(schemas,extra)`, `j.oneOf(schemas,extra)`, `j.anyOf(schemas, extra)`\n\n    let schema = j.allOf(j.array(), { items: 'number' });\n    // =\u003e { allOf: [\n    //      { type: 'array' },\n    //      { items: { type: number } }\n    //    ] }\n\nSame for `oneOf` and `anyOf`.\n\n### `j.not(description?, schema)`\n\n    let schema = j.not(array());\n    // =\u003e { not: { type: 'array' } }\n\n## Shorthands\n\n### Types as string\n\nIf a string `type` is encountered where a property definition is\nexpected, the string is expanded to the object `{ \"type\": type }`.\n\n    {\n        \"foo\": \"number\",\n        \"bar\": \"string\"\n    }\n\nexpands to\n\n    {\n        \"foo\": { \"type\": \"number\" },\n        \"bar\": { \"type\": \"string\" }\n    }\n\nIf the string begins with a `#`, the type is assumed to be a local reference and\n`#type` is expanded to `{ \"$ref\": type }`.\n\n    { \"foo\": \"#/definitions/bar\" }\n\nbecomes\n\n    { \"foo\": { \"$ref\": \"#/definitions/bar\" } }\n\nIf the string begins with a `$`, the type is assumed to be a general reference and\n`$type` is expanded to `{ \"$ref\": type }`.\n\n    { \"foo\": \"$http://foo.com/bar\" }\n\nbecomes\n\n    { \"foo\": { \"$ref\": \"http://foo.com/bar\" } }\n\n### `object` property\n\n`{ object: properties }` expands to `{ type: \"object\", properties }`.\n\n    shorthand                              expanded\n    ------------------------               ---------------------------\n    foo: {                                  foo: {\n        object: {                               type: \"object\",\n            bar: { }                            properties: {\n        }                                           bar: { }\n    }                                           }\n                                            }\n\n### `array` property\n\n`{ array: items }` expands to `{ type: \"array\", items }`.\n\n    shorthand                              expanded\n    ------------------------               ---------------------------\n    foo: {                                  foo: {\n        array: 'number'                         type: \"array\",\n    }                                           items: {\n                                                    type: 'number'\n                                                }\n                                            }\n\n### `required` property\n\nIf the `required` attribute is set to `true` for a property, it is bubbled\nup to the `required` attribute of its parent object.\n\n    shorthand                              expanded\n    ------------------------               ---------------------------\n\n    foo: {                                  foo: {\n        properties: {                           required: [ 'bar' ],\n          bar: { required: true },              properties: {\n          baz: { }                                bar: {},\n        }                                         baz: {}\n    }                                       }\n\nThe type or `$ref` of a field can also be appended a `!` to mark it\nas required.\n\n    shorthand                              expanded\n    ------------------------               ---------------------------\n\n    foo: {                                  foo: {\n        properties: {                           required: [ 'bar', 'baz' ],\n          bar: 'number!'                        properties: {\n          baz: '#baz_type!'                       bar: {   type: 'number' },\n        }                                         baz: { '$ref': '#baz_type' }\n    }                                       }\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanick%2Fjson-schema-shorthand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyanick%2Fjson-schema-shorthand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanick%2Fjson-schema-shorthand/lists"}