New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dts-from-json

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dts-from-json

Command line utility to emit TypeScript type declaration files for JSON files

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-91.67%
Maintainers
0
Weekly downloads
 
Created
Source

dts-from-json

Command line utility to emit TypeScript type declaration files for JSON files powered by

Installation and usage

npm install -g dts-from-json
dts-from-json <json-file>

You can pass a local path or URL as <json-file>.

Save to a file

The types are printed in stdout, to save to a file simply pipe to output to a file:

dts-from-json <json-file> > <dts-dir>

Examples

dts-from-json demo/json/senators.json
dts-from-json https://raw.githubusercontent.com/Biuni/PokemonGO-Pokedex/master/pokedex.json
dts-from-json demo/json/senators.json > demo/types/senators.d.ts 
dts-from-json demo/json/senators.json --root Senators
dts-from-json ./demo/json/senators.json --root Senators --types true

Usage via npx

npx dts-from-json <json-file>

Customize the root type

The default root type is the CamelCase version of the json file name. For example, if your file is called nobe-prize.d.ts the root type will be NobelPrice by default.

$ dts-from-json <json-file> --root Senators

Use type instead of interface

 $ dts-from-json <json-file> --types

Known limitations

  • Using json properties with names that have collisions with other types will cause issues. For example, if you have json that looks like:
{
    "meta": {
        // ...
    },
    "objects": [
        // ...
    ]
}

It will be translated into:

interface Meta {
    // ...
}

interface Object { // <-- Collision with Object type
    // ...
}

interface RootObject {
  meta: Meta;
  objects: Object[];
}

This will lead to problems with the already defined Object type.

Keywords

FAQs

Package last updated on 18 Jul 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc