npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

embed-json-in-ts

v0.0.9

Published

Natural way of importing json files from TypeScript

Downloads

43

Readme

Build Status Dependencies

Natural way of importing json files from TypeScript:

Have a data/data1.json file in the same folder as your .ts sources and just load it:

import {data1} from './data/data1'
console.log(data1.persons[0].name) // no problems with types - data1 is well described by a typescript interface :)

Problem to solve: As a TypeScript developer I want to import the data inside a .json local file naturally from my TypeScript code. Also I want to make sure it get's embedded in the output (so I can bundle its content)

embed-json-in-js is a JSON pre-processing tool that convert .json files into real TypeScript modules for easy importing and embedding.

Install and Use in Command Line

Install:

npm install embed-json-in-ts

Use:

npx embed-json-in-ts --input="src/**/*.json"
npx embed-json-in-ts --mode fs2json --input "./data/**/*.json" --output "src/data" --debug
npx embed-json-in-ts --mode string --input "node_modules/typescript/lib/*.d.ts" --output "./src/typings" --preserveExtension

Install and use in node js project

npm install --save-dev embed-json-in-ts

Use it in your build scripts gulpfile.js or whatever your build system:

var tool = require('embed-json-in-ts')
tool({input: 'src/**/*.json'})

Integrating in existing TypeScript projects

Basically you want to call embed-json-in-ts before the typescript compiler tsc for example in package.json:

"scripts": {
  "build": "node node_modules/embed-json-in-ts/src/cli --input src/**/data/**/*.json && node node_modules/typescript/bin/tsc",

folder to json tool

it will generate a .json file containing a folder contents and then generate the .ts from that:

embed-json-in-ts --mode=fs2json --input="folder/**/*" --output="./data/folder.json"

and then you are ready to:

import {folder} from './data/folder'

Project example:

*see spec/assets/project-watch-handlebars-test1

  • gulp watch, handlebars templates imported using json. in this case template compilation into a json is not responsibility of this project - just the support for importing and embedding.

TODO

  • get input from given tsconfig.json file (current one - since this is a ts project should have one)