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 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsonxt

v0.0.19

Published

JSON External Templates

Downloads

34

Readme

JSON External Templates

JSON-XT compresses JSON documents into short URIs, using eXternal Templates. Depending on the application, these URIs are 25 - 35% of the original JSON document size.

Great for constrained environments, such as encoding data in QR codes.

See jsonxt.io for more, as well as this paper for a lot more explanation.

Installation

Node.JS

npm install jsonxt

Python

pip install jsonxt

Use

Setup (Javascript)

const jsonxt = require("jsonxt")

// sample data…
const original = {
  "@context": {
    "ical": "http://www.w3.org/2002/12/cal/ical#",
    "xsd": "http://www.w3.org/2001/XMLSchema#",
    "ical:dtstart": {
      "@type": "xsd:dateTime"
    }
  },
  "ical:summary": "Lady Gaga Concert",
  "ical:location": "New Orleans Arena, New Orleans, Louisiana, USA",
  "ical:dtstart": "2011-04-09T20:00:00Z"
}
const templates = {
  "simple:1": {
    "columns": [
      {
        "path": "ical:summary", 
        "type": "string"
      }, 
      {
        "path": "ical:location", 
        "type": "string"
      }, 
      {
        "path": "ical:dtstart", 
        "type": "isodatetime-epoch-base32"
      }
    ], 
    "template": {
      "@context": {
        "ical": "http://www.w3.org/2002/12/cal/ical#", 
        "ical:dtstart": {
          "@type": "xsd:dateTime"
        }, 
        "xsd": "http://www.w3.org/2001/XMLSchema#"
      }
    }
  }
}
const TYPE = "simple"
const VERSION = "1"
  • An example original is here
  • An example templates is here

The templates can have multiple compression formats encoded, they will be selected by TYPE and VERSION.

Encoding

This will compress the original JSON payload into a URI

Javascript:

const packed = await jsonxt.pack(original, templates, TYPE, VERSION, "example.com")

Which yields (ignore newline)

jxt:jsonxt.io:simple:1:Lady~Gaga~Concert/
  New~Orleans~Arena%2C~New~Orleans%2C~Louisiana%2C~USA/16Q1EM0

This is a compression of 279 bytes to 101 bytes: 36% of the original size.

See test code for a more fully worked through example.

Decoding

This will decompress the packed URI into the original URI.

Javascript:

const unpacked = await jsonxt.unpack(packed, jsonxt.resolve)

Python (package details being worked out):

unpacked = jsonxt.unpack(packed, jsonxt.resolve)

Resolving

Resolving takes a "resolver name" like example.com embedded in the URI and a file name and retrieves a document.

The following rules are used:

  • if it has a slash or a colon, it's treated a a URL (https:// is assumed if no scheme)
  • otherwise we check https://resolver/.well-known/name

Generally you can just use jsonxt.resolve.

See Also

  • RFC2397 - The "data" URL scheme
  • RFC3986 - URI generic syntax
  • RFC4180 - Common Format and MIME Type for CSV Files
  • RFC8141 - Uniform Resource Names (URNs)