https://github.com/hmmhmmhm/typescript-json
📦 Initialize JSON data according to type schema
https://github.com/hmmhmmhm/typescript-json
init initialization initializer json schema typescript
Last synced: 5 months ago
JSON representation
📦 Initialize JSON data according to type schema
- Host: GitHub
- URL: https://github.com/hmmhmmhm/typescript-json
- Owner: hmmhmmhm
- License: mit
- Created: 2019-10-13T16:21:04.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-05-10T17:17:25.000Z (almost 5 years ago)
- Last Synced: 2025-08-27T16:52:02.230Z (7 months ago)
- Topics: init, initialization, initializer, json, schema, typescript
- Language: TypeScript
- Size: 21.5 KB
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Typescript JSON
> 📦 Initialize JSON data according to type schema
Have you ever had trouble resetting the values you received to the desired form of value when you received any data from the web or server?
The **Typescript JSON** module helps initialize the JSON data to the desired Schema. It also supports Intellisense and Automatic Completion based on Typescript. (This module is a module that binds [scotthovestadt/schema-object]( https://github.com/scotthovestadt/schema-object) to a Typescript.)
## Install
```bash
npm install typescript-json
```
## Usage
```typescript
import {
TypescriptJSON,
Types
} from 'typescript-json'
// Defines the data schema.
let schema = {
// If non-compliant data is entered,
// the value will be replaced with undefined
id: Types.String({
default: 'accountId',
minLength: 6
}),
// Or just can simply specify a format.
pw: Types.String({})
}
// Contains the data to be entered.
let input: any = {}
// Input value of modified
// to schema specification
let data = TypescriptJSON
(schema, input)
console.log(data.id) // 'accountId'
console.log(data.pw) // undefined
// The value does not change because the
// minimum length specification does not comply.
data.id = 'wrong' // need to be more than 6 length.
console.log(data.id) // still 'accountId'
```
## Example

It can define the default value of the id value, define the maximum length, and so on.

Once the data has been initialized, all components of the data can be accessed accurately through Intelligence and Auto Completion.
## License
MIT Licensed.