https://github.com/monolithed/json-to-typescript
Converts a JSON object to TypeScript interfaces
https://github.com/monolithed/json-to-typescript
dts json typescript typings
Last synced: 6 months ago
JSON representation
Converts a JSON object to TypeScript interfaces
- Host: GitHub
- URL: https://github.com/monolithed/json-to-typescript
- Owner: monolithed
- License: mit
- Created: 2017-03-21T23:39:01.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-10-02T19:34:51.000Z (about 2 years ago)
- Last Synced: 2025-03-17T12:06:58.889Z (7 months ago)
- Topics: dts, json, typescript, typings
- Language: TypeScript
- Homepage:
- Size: 97.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# json-to-typescript
> Converts a JSON object to TypeScript interfaces
### Installation
```
npm install json-to-typescript --save
```### Interface
```typescript
type Predicate = (
value: JSONValue,
key: string,
target: Target
) => boolean;declare function transform (
name: string,
json: Target,
filter?: Predicate
): Promise;
```### Usage
```typescript
import { transform } from 'json-to-typescript';const json = {
'x': 0,
'x-1': '1',
'y-2': '2'
};transform('X', json);
```**Output**
```typescript
export interface X {
x?: number;
"x-1"?: string;
"y-2": string
[x: string]: any;
}
```#### Filter
Use the last param to filter your properties:
```typescript
import { transform } from 'json-to-typescript';const json = {
'x': 0,
'x-1': '1',
'y-2': '2'
};const filter = (value: any) => value !== '2';
transform('X', json, filter);
```**Output**
```typescript
export interface X {
x?: number;
"x-1"?: string;
}
```### Contributing
Feel free to submit a pull request if you find any bugs.
Please make sure all commits are properly documented.### Tests
```
npm test
```### License
MIT