
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
Automatically generate Typescript Definition files or Flow types from JSON input
npm install -g json-tsAutomatically generate Typescript Definition files or Flow types from JSON input.
Use it via the API, CLI, or Website

| Feature | json-ts (this library) | json-to-ts | json2ts |
|---|---|---|---|
| simple literal types (number, string etc) | YES | YES | YES |
| array type, all elements of same kind | YES | YES | YES |
| merge multiple json files | YES (cli, v1.6 & above) | NO | NO |
| optional members | YES | YES | NO |
| array union types | YES | YES | NO |
| correct handling of top-level values (strings, arrays, arrays of objects numbers etc) | YES | NO | NO |
| recursive data structures (see here) | YES | NO | NO |
| nested type literals (to account for invalid interface names) | YES | YES | NO |
| output @flow types | YES | NO | NO |
| Website | YES | YES | YES |
| CLI | YES | NO | NO |
| API | YES | YES | NO |
# install
npm install -g json-ts
# run against a single JSON file
json-ts dir/myfile.json
# run against multiple single JSON files (interfaces will be merged)
json-ts api/resp1.json api/resp2.json
Note: only stdin (which requires the --stdin flag) & filepaths are supported right now. Later I will add support for Windows, reading data from network requests etc.
## piping via stdin
curl https://jsonplaceholder.typicode.com/posts/1 | json-ts --stdin
## reading single json file from disk
json-ts my-file.json
## reading multiple json files from disk
json-ts my-file.json my-other-file.json
... produces the following:
interface IRootObject {
userId: number;
id: number;
title: string;
body: string;
}
npm install json-ts --save-dev
const { json2ts } = require('json-ts');
const json = `
{
"name": "Shane"
}
`;
console.log(json2ts(json))
... produces the following:
interface IRootObject {
name: string;
}
For more examples, see the Tests
# usage
json-ts <filename> --namespace <namespace_name>
# example
json-ts data/my-file.json --namespace API
# usage
json-ts <filename> --flow
# example
json-ts data/my-file.json --flow
I prefix on interface names
# usage
json-ts <filename> --prefix <prefix_string>
# example (remove prefix)
json-ts data/my-file.json --prefix ""
RootObject name of the top-level interface
# usage
json-ts <filename> --rootName <rootname_string>
# example
json-ts data/my-file.json --rootName "Product"
I prefix on interface names--flownums: [1, "2"] -> nums: number|string[]
(already works for complex objects) declare namespace Projects {
export interface ILoc {
lat: number;
lng: number;
}
...
}
--stdin flag)FAQs
Automatically generate Typescript Definition files or Flow types from JSON input
The npm package json-ts receives a total of 2,354 weekly downloads. As such, json-ts popularity was classified as popular.
We found that json-ts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.