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

jsonpc-ts

v0.4.2

Published

This is a lightweight JSON variant that allows comments under certain conditions.

Readme

JSON with Property Comments — A lightweight JSON variant that allows single-line comments // and trailing commas in JSON files.

npm version npm downloads License: MIT Codacy Badge

Syntax

jsonpc follows these rules for comment:

  1. Trailing commas in arrays and objects are allowed
  2. Only single-line comments starting with // are supported
  3. Comments must occupy an entire line
  4. Multiple consecutive comment lines are allowed
  5. Valid comment positions:
    1. Top of the file (before any JSON content)
    2. Bottom of the file (after all JSON content)
    3. Above property names

Other positions and block comments are not allowed.

Examples

// ✅ Valid: Top-level file comment
// ✅ Valid: Multiple consecutive comments allowed
{
  // ✅ Valid: Comment above property name
  "name": "Alice",

  // ✅ Valid: Comment above array element (primitive)
  "items": [
    // ❌ Invalid: Comment not above a property
    1,
    2,
  ],

  "users": [
    {
    // ✅ Valid: Comment above object property in array
    // ✅ Valid: 1 Multiple consecutive comments allowed
    // ✅ Valid: 2 Multiple consecutive comments allowed
      "name": "Bob"
    },
    // ❌ Invalid: Comment not above a property
    "sdaf"
  ],

  /* ❌ Invalid: Block comments not supported */
  "key": "value",
  // ❌ Invalid: Comment not above a property
}
// ✅ Valid: Bottom-level file comment

Usage

import { parse } from 'jsonpc-ts';

// Parse jsonpc text into an operatable instance
const jsonpc = parse(text);

// Get both value and comments for a property path
const entry = jsonpc.get('profile');
// → { value: { age: 25 }, comments: ['// Nested object comment'] }

// Get value only
const name = jsonpc.get('name')?.value;    // → "Alice"
const age = jsonpc.get('profile.age')?.value; // → 25
const age2 = jsonpc.get(['profile','age'])?.value; // → 25

// Get comments only
const comments = jsonpc.get('name')?.comments;
// → ['// This is a name comment']

// Handle non-existent paths
const entry = jsonpc.get('nonexistent');
// → undefined

jsonpc.set('profile', {
  value: { age: 26 },
  comments: ['Updated profile comment']
});
// Sets 'profile' to be an object with age 26 and updates its comments


// Set top-level comments
jsonpc.top = ['// New top comment'];

// Set bottom-level comments
jsonpc.bottom = ['// New bottom comment'];

Top and Bottom File Comments

import { parse } from 'jsonpc-ts';

const jsonpc = parse(text);

// Get top-level file comments
const topComments = jsonpc.top;
// → ['// This is a top comment', '// Another top comment']

// Get bottom-level file comments  
const bottomComments = jsonpc.bottom;
// → ['// This is a bottom comment']

// Get/Set top-level comments
jsonpc.top = ['New top comment'];

// Get/Set bottom-level comments
jsonpc.bottom = ['New bottom comment'];

// Release internal references and clear internal containers
jsonpc.destroy();

Serialization

// Serialize back to JSON text with comments
const output = jsonpc.stringify();

// Custom indentation and replacer
const custom = jsonpc.stringify(null, 4);

// Get clean JSON object without comments
const clean = jsonpc.toObject();
// → { name: "Alice", profile: { age: 25 }, items: [1, 2] }

Comparison with Alternatives

| Solution | Custom Parser | Arbitrary Position Comments | Trailing Commas | Size | | ---------- | ------------- | --------------------------- | --------------- | ------ | | jsonpc | ❌ | ❌ | ✅ | Small | | json5 | ✅ | ✅ | ✅ | Large | | JSONC | ✅ | ✅ | ❌ | Medium |

jsonpc trades some flexibility for simplicity and performance by:

  • Only allowing comments at specific, predictable positions (above properties)
  • Using standard JSON parsing with comment pre-processing
  • Maintaining a lightweight codebase

License

MIT

Contributing

Issues and Pull Requests are welcome!

Related Links