{"id":13439410,"url":"https://github.com/zth/json-to-flowtype-generator","last_synced_at":"2025-03-20T08:30:57.858Z","repository":{"id":57285378,"uuid":"113751325","full_name":"zth/json-to-flowtype-generator","owner":"zth","description":"Generate Flow types from JSON or static JS objects/arrays.","archived":false,"fork":false,"pushed_at":"2017-12-12T17:01:41.000Z","size":81,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T06:11:25.451Z","etag":null,"topics":["flowtype","javascript","json"],"latest_commit_sha":null,"homepage":null,"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/zth.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2017-12-10T13:16:26.000Z","updated_at":"2023-01-05T01:14:31.000Z","dependencies_parsed_at":"2022-09-10T09:02:29.733Z","dependency_job_id":null,"html_url":"https://github.com/zth/json-to-flowtype-generator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Fjson-to-flowtype-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Fjson-to-flowtype-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Fjson-to-flowtype-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Fjson-to-flowtype-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zth","download_url":"https://codeload.github.com/zth/json-to-flowtype-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244341672,"owners_count":20437702,"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":["flowtype","javascript","json"],"created_at":"2024-07-31T03:01:13.665Z","updated_at":"2025-03-20T08:30:57.530Z","avatar_url":"https://github.com/zth.png","language":"JavaScript","funding_links":[],"categories":["HarmonyOS"],"sub_categories":["Windows Manager"],"readme":"# json-to-flowtype-generator\nThis is a small tool to generate `flow` types from arbitrary JSON or static JS objects/arrays.\nThe tool was designed with the following use cases in mind:\n\n* Generating base types for API calls\n* Quickly generating types from arbitrary JS objects, lists or JSON\n\nIt provides easy interaction by defaulting to using the current clipboard contents, effectively making the workflow:\n\n1. Copy your data\n2. Run `json-to-flow` in a terminal\n3. The generated type has now been copied to the clipboard\n\nIt can also operate directly on files, as in the example below:\n\n![Example usage](https://raw.githubusercontent.com/zth/json-to-flowtype-generator/master/example.gif \"Example usage\")\n\nThe tool does some semi-intelligent merging of objects etc in lists in order to identify both `maybe`-keys and keys that can have multiple types. \nCheck out the GIF above and compare the objects in `friends` of the raw data to `friends` in the generated type. Notice how the tool has marked keys \nnot present in all objects as `maybe` types.\n\n## Installation\n```\nnpm install -g json-to-flowtype-generator\njson-to-flow -h\n```\n\n## Usage\n```\n# This will use the file apiResponse.json to generate a Flow type, and let you set options for the type interactively.\njson-to-flow --file apiResponse.json --interactive\n```\n\n```\n# This will use the current clipboard content to generate a Flow type, make the type read only, and name it ApiResponse.\njson-to-flow --clipboard --read-only --name ApiResponse\n```\n\nAll commands have shortcuts, check out `json-to-flow -h`.\n\n## Editor integrations\nI personally use IntelliJ/WebStorm, but other editor integrations are very welcome contributions.\n\n### IntelliJ/WebStorm/JetBrains\nYou can configure an `External Tool` that runs `json-to-flow --clipboard` + your desired config. \nThen simply copy an object/array/some JSON and run the external tool.\n\n## Merging of lists and objects\nThe tools tries to be as smart as possible with merging lists and objects. \nFor example, it assumes that objects discovered in the same list are of the same type, \nmerging the objects into one and sensing what properties are present on all objects,\nand what are not and therefore are optional. This is desirable all cases where the objects returned\nin a list is in fact of the same type. Currently there's no way to turn this off, but it might come \nin a later version.\n\nExample:\n\n```\n{\n    friends: [\n        {\n            name: \"Name\", // This is present in all objects\n            email: \"email@email.com\" // But this isn't\n        },\n        {\n            name: \"Name 2\"\n        },\n        {\n            name: \"Name 3\"\n        }\n        ....\n    ]\n}\n```\n\nBecomes:\n\n```\ntype Type = {|\n    +friends: $ReadOnlyArray\u003c{|\n        +name: string,\n        +email: ?string\n    |]\u003e\n|}\n```\n\nIt also handles the same key having multiple types of values in different objects \nin the same list. Check out the tests for more info.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzth%2Fjson-to-flowtype-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzth%2Fjson-to-flowtype-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzth%2Fjson-to-flowtype-generator/lists"}