Skip to content

jyelewis/json-to-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON to TypeScript

Just a little hack project to keep my C skills sharp. I don't intend to maintain this, and while it has tests, no guarantee of it's stability or security 🙃

Purpose

Converts JSON

{
  "pagination": {
    "results": 152,
    "limit": 2,
    "skipped": 0
  },
  "users": [
    {
      "firstName": "John",
      "lastName": "Smith",
      "profileImage": "https://picsum.photos/200",
      "recentLogins": [
        1631391272,
        1631393555
      ],
      "premiumUser": false,
      "favouriteProperties": [
        {
          "address": "123 fake street",
          "suburb": "Springfield",
          "country": "USA",
          "rating": 5
        }
      ]
    },
    {
      "firstName": "Jane",
      "lastName": "Doe",
      "profileImage": null,
      "premiumUser": true,
      "favouriteProperties": [
        {
          "address": "456 second avenue",
          "suburb": "Columbus",
          "state": "OH",
          "country": "USA",
          "rating": 4
        }
      ]
    }
  ]
}

To a matching TypeScript type:

export type JsonData = {
    pagination: {
        results: number;
        limit: number;
        skipped: number;
    };
    users: Array<{
        firstName: string;
        lastName: string;
        profileImage: null | string;
        recentLogins?: number[];
        premiumUser: boolean;
        favouriteProperties: Array<{
            address: string;
            suburb: string;
            country: string;
            rating: number;
            state?: string;
        }>;
    }>;
};

Performance

Designed to be highly performant with a small memory footprint.

Can convert ~135,000 files per second.

Building

Use CMake to build

For convenience, a build.sh is present in the repository to configure & build a binary from source.

Usage

Once compiled, the binary will take JSON via stdin, and provide typescript vis stdout. e.g.

curl https://api.my-example-app.com/books.json | json-to-ts > Books.ts

Tests

Tests are implemented in JavaScript.

The application must be built before tests can run

Run ./test.sh to build & execute all tests

About

A C application for generating Typescript type definitions from JSON

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages