{"id":21475821,"url":"https://github.com/shakyshane/json-ts","last_synced_at":"2025-04-05T03:04:44.475Z","repository":{"id":41677217,"uuid":"91686639","full_name":"shakyShane/json-ts","owner":"shakyShane","description":"Automatically generate Typescript Definition files or Flow types from JSON input.","archived":false,"fork":false,"pushed_at":"2023-03-17T14:57:59.000Z","size":1199,"stargazers_count":217,"open_issues_count":9,"forks_count":17,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-14T07:49:48.703Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://shakyshane.github.io/json-ts/","language":"JavaScript","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/shakyShane.png","metadata":{"files":{"readme":"readme.md","changelog":null,"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":"2017-05-18T11:43:25.000Z","updated_at":"2024-06-18T13:46:05.234Z","dependencies_parsed_at":"2024-06-18T13:45:56.006Z","dependency_job_id":"f80ea3f7-7dde-40ca-bb9d-e7f24a3065f6","html_url":"https://github.com/shakyShane/json-ts","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shakyShane%2Fjson-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shakyShane%2Fjson-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shakyShane%2Fjson-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shakyShane%2Fjson-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shakyShane","download_url":"https://codeload.github.com/shakyShane/json-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247280262,"owners_count":20912967,"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","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":[],"created_at":"2024-11-23T10:46:13.643Z","updated_at":"2025-04-05T03:04:44.454Z","avatar_url":"https://github.com/shakyShane.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/shakyShane/json-ts.svg?branch=master)](https://travis-ci.org/shakyShane/json-ts)\n\n## `npm install -g json-ts`\n\n\u003e Automatically generate Typescript Definition files or Flow types from JSON input. \n\n\u003e Use it via the API, CLI, or [Website](https://shakyshane.github.io/json-ts/)\n \n![json-ts](https://cdn.rawgit.com/shakyShane/json-ts/37ce9b2b/json-ts2.gif)\n\n### How does **json-ts** stack up against the competition?\n\n|Feature   |json-ts (this library)  |[json-to-ts](https://github.com/MariusAlch/json-to-ts)   |[json2ts](http://json2ts.com/)  |\n|---|---|---|---|\n|simple literal types (number, string etc) |**YES**   |YES   |YES   |\n|array type, all elements of same kind |**YES**   |YES   |YES   |\n|merge multiple json files|**YES (cli, v1.6 \u0026 above)**   |NO   |NO   |\n|optional members | **YES** | YES | NO |\n|array union types | **YES**   |YES   |NO   |\n|correct handling of top-level values ([strings](https://shakyshane.github.io/json-ts/#src=%22some-api-token-as-string%22), [arrays](https://shakyshane.github.io/json-ts/#src=%5B1%2C%202%2C%203%5D), [arrays of objects](https://shakyshane.github.io/json-ts/#src=%5B%0A%20%20%7B%22name%22%3A%20%22shane%22%7D%2C%0A%20%20%7B%22name%22%3A%20%22kittie%22%2C%20%22age%22%3A%2030%7D%0A%5D), [numbers](https://shakyshane.github.io/json-ts/#src=1) etc) |**YES**   |NO   |NO   |\n|recursive data structures ([see here](https://github.com/shakyShane/json-ts/blob/master/__tests__/magento/categories.json)) |**YES**   |NO   |NO   |\n|nested type literals (to account for invalid [interface names](https://github.com/shakyShane/json-ts/blob/master/__tests__/swagger/schema.json)) |**YES**   |YES   |NO   |\n|output @flow types |**YES**   |NO   |NO   |\n|Website |**[YES](https://shakyshane.github.io/json-ts/)**   |[YES](http://www.jsontots.com/)   |[YES](http://json2ts.com/)   |\n|CLI |**YES**   |NO   |NO   |\n|API |**YES**   |YES   |NO   |\n \n## Quick-start\n```bash\n# install\nnpm install -g json-ts\n\n# run against a single JSON file\njson-ts dir/myfile.json\n\n# run against multiple single JSON files (interfaces will be merged)\njson-ts api/resp1.json api/resp2.json\n```\n\n## Usage (CLI)\nNote: only stdin (which requires the --stdin flag) \u0026 filepaths are supported right now. \nLater I will add support for Windows, reading data from network requests etc.\n\n```bash\n## piping via stdin\ncurl https://jsonplaceholder.typicode.com/posts/1 | json-ts --stdin\n\n## reading single json file from disk\njson-ts my-file.json\n\n## reading multiple json files from disk\njson-ts my-file.json my-other-file.json\n```\n\n... produces the following: \n\n```ts\ninterface IRootObject {\n  userId: number;\n  id: number;\n  title: string;\n  body: string;\n}\n```\n\n## Usage (API)\n\n```bash\nnpm install json-ts --save-dev\n```\n\n```js\nconst { json2ts } = require('json-ts');\nconst json = `\n{\n    \"name\": \"Shane\"\n}\n`;\nconsole.log(json2ts(json))\n```\n\n... produces the following:\n\n```ts\ninterface IRootObject {\n  name: string;\n}\n```\n\nFor more examples, see the [Tests](https://github.com/shakyShane/json-ts/tree/master/__tests__) \n\n## Options\n\n - **namespace: string** - if provided, interfaces will be wrapped in a namespace (see below)\n    ```bash\n    # usage\n    json-ts \u003cfilename\u003e --namespace \u003cnamespace_name\u003e \n    \n    # example\n    json-ts data/my-file.json --namespace API\n    ```\n - **flow: boolean** - output types in Flow format.\n    ```bash\n    # usage\n    json-ts \u003cfilename\u003e --flow \n    \n    # example\n    json-ts data/my-file.json --flow\n    ```\n - **prefix: string** - override the `I` prefix on interface names\n    ```bash\n    # usage\n    json-ts \u003cfilename\u003e --prefix \u003cprefix_string\u003e \n    \n    # example (remove prefix)\n    json-ts data/my-file.json --prefix \"\"\n    ```\n - **rootName: string** - override the `RootObject` name of the top-level interface\n    ```bash\n    # usage\n    json-ts \u003cfilename\u003e --rootName \u003crootname_string\u003e \n    \n    # example\n    json-ts data/my-file.json --rootName \"Product\"\n    ```\n\n## TODO:\n\n### options\n\n- [x] Allow choice of `I` prefix on interface names\n- [x] Allow naming of RootObject\n- [ ] Allow choice of spaces/tabs\n\n### Core\n- [x] support array types\n- [x] support boolean types\n- [x] support null types\n- [x] output types for Flow via `--flow`\n- [x] PascalCase as default for all interface names\n- [x] de-dupe interfaces (it's dumb atm, POC)\n- [x] de-dupe interfaces where propname differs, but members are the same\n- [x] merge interfaces by creating union types for members\n- [x] union types for array that contain mixed literal types: `nums: [1, \"2\"] -\u003e nums: number|string[]`\n      (already works for complex objects)\n- [x] quoted member names when needed\n- [x] handle invalid name for interface\n- [x] support type alias declarations\n- [x] Use Typescript factory methods/printer for output \n- [x] Allow wrapping in namespace: eg:\n    ```ts\n        declare namespace Projects {\n            export interface ILoc {\n               lat: number;\n               lng: number;\n            }\n            ...\n        }\n    ```\n    \n### CLI\n- [x] CLI tool to accept stdin (with `--stdin` flag)\n- [x] CLI tool to accept json file as input\n- [ ] CLI tool to accept URL as input (for validating against remote API)\n- [ ] configurable output (filename/stdout etc)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshakyshane%2Fjson-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshakyshane%2Fjson-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshakyshane%2Fjson-ts/lists"}