Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mike-north/json-typescript
TypeScript type definitions for JSON objects
https://github.com/mike-north/json-typescript
Last synced: about 1 month ago
JSON representation
TypeScript type definitions for JSON objects
- Host: GitHub
- URL: https://github.com/mike-north/json-typescript
- Owner: mike-north
- Created: 2017-12-15T23:56:09.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-10-29T18:04:58.000Z (about 1 month ago)
- Last Synced: 2024-10-29T20:11:26.070Z (about 1 month ago)
- Language: TypeScript
- Size: 1.3 MB
- Stars: 30
- Watchers: 3
- Forks: 6
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
- stars - json-typescript - north | 30 | (TypeScript)
- stars - json-typescript - north | 30 | (TypeScript)
README
# JSON-typescript
TypeScript type information for compile-time validation of [JSON objects](https://www.json.org/).
[![Build Status](https://travis-ci.org/mike-north/json-typescript.svg?branch=master)](https://travis-ci.org/mike-north/json-typescript)
[![Version](https://img.shields.io/npm/v/json-typescript.svg)](https://www.npmjs.com/package/json-typescript)## How to use this
1. Install this package
```js
npm install --save-dev json-typescript
```2. Import this package
```ts
import * as _JSON from 'json-typescript';
```3. Check to see if json types are validated correctly
```ts
import * as { Value as JSONValue, Object as JSONObject } from 'json-typescript';// ✅ This should be OK
let doc: JSONValue = {
data: {
type: 'articles',
id: '1'
}
};// ⛔️ This should NOT be OK ( functions are not allowed )
let doc: JSONValue = {
foo() {
return bar;
}
};// ⛔️ This should NOT be OK ( Array is not a JSONObject )
let doc: JSONObject = [];
```## Copyright
© 2018 [Mike North](https://github.com/mike-north), All Rights Reserved.