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 🙏

© 2025 – Pkg Stats / Ryan Hefner

json-uri

v0.1.0

Published

Small and browser-compatible url-friendly JSON translator

Downloads

15

Readme

json-uri

json-uri is a simple uri-compatible json translator with notable advantages:

  • Browser-compatible with no dependencies and size of less than 1kB
  • 25% ~ 40% size deduction when uri-encoded, comparing to uri-encoded JSON string

json-uri searches for unused characters in provided string, and then replaces most commonly seen characters ({ } . : etc.) and sequences ("," ":" etc.) in JSON strings with them. This provides significant improvement on encoded string length with reasonable cost.

json-uri has some difference from similar packages like json-url and juri:

  • It doesn't concern about readability. JSON strings are rarely readable without multi-line formatting, so as a single-line string, trying to keep encoded string readable is commonly useless.
  • It doesn't apply compressing algorithm or other complex methods to further reduce encoded length, for following reasons:
    • most common usage of uri-compatible json translating is to pass JSON objects through web urls, and
    • url parameters longer than 2kB or 4kB are usually considered unsafe due to browser and server limitations, so
    • it is necessary to reduce a 1000-byte encoded string to 700 byte, but not from 700 byte to 680 byte with a lot more code.
  • It doesn't accept custom dictionaries, because it introduces extra coupling into your code. Just use shorter parameter names if you need.

Usage

Encode:

var ju = require('json-uri');
var jsonStr = JSON.stringify(obj);
var encodedStr = ju.encode(jsonStr);
window.location.href = 'http://example.com/?' + encodeURIComponent(encodedStr);

Decode:

var param = window.location.search.slice(1);
var encodedStr = decodeURIComponent(param);
var decodedStr = ju.decode(encodedStr);
var obj = JSON.parse(decodedStr);

API

var ju = require('json-uri');

  • ju.encode(str)

    Encode JSON string to json-uri string.

    • str string JSON string to be encoded
  • ju.decode(str)

    Decode json-uri string to JSON string.

    • str string json-uri string to be decoded
    • throws SyntaxError when the given string is of wrong format

TODO

  • Add more test cases.