typed-json-parse
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

Typed JSON Parse

Summary

This package overrides the default JSON.parse() types with a JSON parser built in TypeScript types, meaning if you put a valid string literal in, you will get the actual type it represents or a somewhat useful error message.

import "typed-json-parse"

const value = JSON.parse('{ "Hello": "NPM!", "foo": [true, 123] }')

// With the actual type of value being:
const value: {
  Hello: string,
  foo: (boolean | number)[]
}

But that's useless

Correct. Since you have the literal string, just use the contents in JS/TS. As a tiny bonus, any non-literal string produces unknown instead of any.

So, why?

I was bored.

Package Sidebar

Install

npm i typed-json-parse

Weekly Downloads

3

Version

0.1.1

License

GLWTPL

Unpacked Size

7.97 kB

Total Files

4

Last publish

Collaborators

  • stefan-terdell