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

rough-json

v0.1.0

Published

A lightweight rough JSON parser that returns a typed AST instead of fully decoded values.

Readme

rough-json

A tiny TypeScript parser that reads JSON text and returns a rough AST (RoughJson) instead of fully decoded runtime values.

This project exists to avoid silent numeric incompatibility between runtimes. JSON specifies how a number literal looks in text, but it does not require every runtime to materialize that literal into the same in-memory numeric type. In JavaScript, JSON.parse maps numbers to number (IEEE 754 double), which can lose precision for large integers. Other compliant implementations may preserve larger integer ranges, so preserving the original token text helps you choose decoding rules explicitly when interoperability matters.

This is useful when you want to:

  • keep the original token text for numbers/strings,
  • preserve number lexemes first, then decode with runtime-specific precision rules,
  • inspect value shapes without converting to plain objects,
  • build custom tooling (formatters, analyzers, migration scripts).

What you get

  • parseRoughly(text) entry point
  • typed AST node union (RoughJson)
  • explicit node types for null, boolean, number, string, array, object
  • a dedicated InvalidJsonError for parse failures

Install

npm

npm install rough-json

The npm package is published as compiled ESM JavaScript with declaration files:

  • runtime: dist/rough-json.js
  • types: dist/rough-json.d.ts

Deno

Import directly from this repository file or your local copy:

import { parseRoughly } from "./rough-json.ts";

Quick example

import { parseRoughly } from "rough-json";

const ast = parseRoughly('{"name":"Ada","active":true,"score":12.5}');

console.log(ast);

High-level shape of the result:

{
  type: "object",
  items: [
    {
      key: { type: "string", text: '"name"' },
      value: { type: "string", text: '"Ada"' }
    },
    {
      key: { type: "string", text: '"active"' },
      value: { type: "boolean", value: true }
    },
    {
      key: { type: "string", text: '"score"' },
      value: { type: "number", text: "12.5" }
    }
  ]
}

API

parseRoughly(text: string): RoughJson

Parses one JSON value at the current start position (after leading whitespace) and returns a typed AST node.

Throws InvalidJsonError if parsing fails.

Exported types

  • RoughJson
  • RoughNull
  • RoughBoolean
  • RoughNumber
  • RoughString
  • RoughArray
  • RoughObject
  • RouthJsonKeyValue

AST reference

type RoughJson =
  | RoughNull
  | RoughBoolean
  | RoughNumber
  | RoughString
  | RoughArray
  | RoughObject;

interface RoughNull {
  type: "null";
}

interface RoughBoolean {
  type: "boolean";
  value: boolean;
}

interface RoughNumber {
  type: "number";
  text: string;
}

interface RoughString {
  type: "string";
  text: string;
}

interface RoughArray {
  type: "array";
  items: RoughJson[];
}

interface RoughObject {
  type: "object";
  items: RouthJsonKeyValue[];
}

interface RouthJsonKeyValue {
  key: RoughString;
  value: RoughJson;
}

Scripts

From package.json:

  • npm run clean -> remove dist
  • npm run build -> compile rough-json.ts to dist/*.js and dist/*.d.ts
  • npm run typecheck -> run TypeScript type-check without emit
  • npm run fmt -> format source with Deno formatter
  • npm run lint -> lint source with Deno linter
  • npm run check -> run Deno check plus TypeScript type-check
  • npm run test -> run Deno tests
  • npm run verify -> run fmt, lint, check, test, build in sequence
  • npm run prepack -> run full verification before npm packing/publishing

From deno.json:

  • deno task build
  • deno task fmt
  • deno task lint
  • deno task check
  • deno task test
  • deno task verify

Current parser behavior and limitations

This parser is intentionally small and currently favors simplicity over strict JSON compliance.

  • It parses a value from the beginning (after leading whitespace), but does not enforce end-of-input after that value.
  • Number parsing is permissive (-, digits, ., e, E) and does not fully validate the complete JSON number grammar.
  • RoughNumber.text keeps the exact source token so you can apply your own numeric decoding policy (for example, to align JavaScript with runtimes that preserve larger integer precision).
  • String nodes keep raw token text; text includes surrounding quotes.
  • Escape handling in strings is minimal.
  • Object keys must be JSON strings.

If you need strict RFC-compliant parsing, use a strict JSON parser and treat this package as an AST-oriented utility.

Development

deno task verify

or

npm run verify