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

@osmix/json

v0.0.7

Published

Convert OSM PBF files to and from JSON.

Readme

@osmix/json

Convert OpenStreetMap PBF bytes to ergonomic JSON entities (and back again) for streaming editors, change workflows, and browser-based tooling. Builds on @osmix/pbf primitives while staying friendly to modern runtimes.

Highlights

  • Decode .osm.pbf streams into header metadata and strongly typed node/way/relation JSON.
  • Encode JSON entities back into spec-compliant PBF blobs with automatic string tables and delta encoding.
  • Stream using Web Stream transforms to keep large datasets out of memory.
  • Compose with other Osmix packages for complete read-modify-write workflows.

Installation

bun add @osmix/json

Usage

Decode a PBF stream

import { osmPbfToJson } from "@osmix/json"
import { toAsyncGenerator } from "@osmix/pbf"

const stream = osmPbfToJson(Bun.file('./monaco.pbf').stream())

for await (const item of toAsyncGenerator(stream)) {
	if ("id" in item) {
		// item is OsmNode | OsmWay | OsmRelation
		console.log(item.id, item.tags?.name)
	} else {
		// item is OsmPbfHeaderBlock
		console.log("Features:", item.required_features)
	}
}

Encode JSON to PBF

import { osmJsonToPbf } from "@osmix/json"

// Create header
const header = {
	required_features: ["OsmSchema-V0.6", "DenseNodes"],
	optional_features: [],
}

// Create entity generator
async function* generateEntities() {
	yield { id: 1, lon: -122.4, lat: 47.6, tags: { name: "Seattle" } }
	yield { id: 2, lon: -122.3, lat: 47.5 }
	yield { id: 10, refs: [1, 2], tags: { highway: "primary" } }
}

// Convert to PBF stream
const pbfStream = osmJsonToPbf(header, generateEntities())
await Bun.write('./output.pbf', pbfStream)

Using TransformStreams

import {
	OsmBlocksToJsonTransformStream,
	OsmJsonToBlocksTransformStream,
} from "@osmix/json"
import {
	OsmPbfBytesToBlocksTransformStream,
	OsmBlocksToPbfBytesTransformStream,
} from "@osmix/pbf"

// Decode: bytes → blocks → JSON entities
const jsonStream = pbfBytes
	.pipeThrough(new OsmPbfBytesToBlocksTransformStream())
	.pipeThrough(new OsmBlocksToJsonTransformStream())

// Encode: JSON entities → blocks → bytes
const pbfStream = entityStream
	.pipeThrough(new OsmJsonToBlocksTransformStream())
	.pipeThrough(new OsmBlocksToPbfBytesTransformStream())

API

Decoding (PBF → JSON)

| Export | Description | |--------|-------------| | osmPbfToJson(stream) | Convert PBF bytes to stream of header + JSON entities | | OsmBlocksToJsonTransformStream | TransformStream: primitive blocks → JSON entities | | blocksToJsonEntities(block) | Generator: extract entities from a single block | | OsmPbfBlockParser | Class for parsing blocks with configurable options |

Encoding (JSON → PBF)

| Export | Description | |--------|-------------| | osmJsonToPbf(header, entities) | Convert header + entities to PBF byte stream | | OsmJsonToBlocksTransformStream | TransformStream: JSON entities → primitive blocks | | jsonEntitiesToBlocks(entities) | Async generator: entities → blocks | | OsmPbfBlockBuilder | Class for building blocks from entities |

Types

| Export | Description | |--------|-------------| | ParseOptions | Options for OsmPbfBlockParser (parseTags, includeInfo) | | OSM_ENTITY_TYPES | Array: ["node", "way", "relation"] |

Related Packages

Environment and Limitations

  • Requires Web Streams, TextEncoder/TextDecoder (Bun, Node 20+, modern browsers).
  • Expects zlib-compressed blobs; other compression formats are not supported.
  • JSON → PBF pipelines assume sorted entities (nodes, then ways, then relations).

Development

bun run test packages/json
bun run lint packages/json
bun run typecheck packages/json

Run bun run check at the repo root before publishing.