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

rsc-to-json

v1.0.1

Published

A TypeScript library for parsing React Server Components (RSC) network payloads into JSON

Readme

RSC to JSON

A TypeScript library for parsing React Server Components (RSC) network payloads into JSON.

Features

  • 🚀 Full RSC Support: Parse all RSC chunk types (imports, models, errors, hints)
  • 🔗 Reference Resolution: Automatically resolve $L references into nested JSON
  • 📦 Dual Module Support: Works with both CommonJS and ES Modules
  • 🎯 Type Safe: Written in TypeScript with full type definitions
  • 🧪 Well Tested: Comprehensive test suite with real-world examples

Installation

npm install rsc-to-json

# For global CLI usage
npm install -g rsc-to-json

Quick Start

import { parseRSC } from 'rsc-to-json';

const rscPayload = `
170:["John Doe - Software Engineer"]
1d7:[{"name":"Global Cybersecurity Advisor","title":"CISSP, CCSP","bio":"$L170"}]
0:[["$","div",null,{"className":"profile","children":"$L1d7"}]]
`;

const result = parseRSC(rscPayload);
console.log(JSON.stringify(result.root, null, 2));

Output:

{
  "type": "div",
  "props": {
    "className": "profile",
    "children": {
      "name": "Global Cybersecurity Advisor",
      "title": "CISSP, CCSP",
      "bio": "John Doe - Software Engineer"
    }
  }
}

CLI Usage

Convert RSC files to JSON from the command line:

# Basic usage
rsc-to-json input.rsc output.json

# With options
rsc-to-json input.rsc output.json --no-pretty

# Show help
rsc-to-json --help

CLI Options

  • --pretty - Pretty print JSON output (default: true)
  • --no-pretty - Output compact JSON
  • --help, -h - Show help message

Example

# Create an RSC file
echo '170:["John Doe"]
0:[["$","div",null,{"children":"$L170"}]]' > test.rsc

# Convert to JSON
rsc-to-json test.rsc output.json

# View the result
cat output.json

API Reference

parseRSC(payload: string): ResolvedRSCData

Parse and resolve an RSC payload in one step.

const result = parseRSC(rscPayload);

RSCParser

For more control, use the parser class directly:

import { RSCParser, resolveReferences } from 'rsc-to-json';

const parser = new RSCParser();
const parsed = parser.parse(rscPayload);
const resolved = resolveReferences(parsed);

Types

interface ImportInfo {
  id: string;
  moduleId: string;
  exports: string[];
  name: string;
}

interface ComponentInfo {
  id: string;
  type: 'ReactElement' | 'ComplexComponent' | 'Unknown';
  element?: string;
  props?: Record<string, any>;
  children?: any;
  metadata?: any;
}

interface ParsedRSCData {
  imports: Map<string, ImportInfo>;
  components: Map<string, ComponentInfo>;
  references: Map<string, string>;
  rootComponent?: ComponentInfo;
}

interface ResolvedRSCData {
  imports: Record<string, ImportInfo>;
  components: Record<string, any>;
  root?: any;
  references?: Record<string, string>;
}

Understanding RSC Format

React Server Components use a line-based format for streaming UI:

Import Chunks

1:I["moduleId",[],"ComponentName"]
  • Imports a component for use in the payload

Model Chunks

0:[["$","div",null,{"children":"Hello"}]]
  • Defines UI components and data

References

$L170  // References component with ID 170
$L1    // References import with ID 1

Special Values

$undefined  // Represents undefined value

Advanced Usage

Parsing Without Resolution

const parser = new RSCParser();
const parsed = parser.parse(rscPayload);

// Access raw parsed data
console.log(parsed.imports);     // Map of imports
console.log(parsed.components);  // Map of components
console.log(parsed.references);  // Map of references

Handling Complex Payloads

// Complex application RSC payload with imports
const complexPayload = `
1:I["030d6035cb3a997efb1cff7a008d2f89",[],"default"]
17:I["b55b61101826bcdf8a734370f7480e4e",[],"VisibleItemsProvider"]
2:["$","div",null,{"className":"container","children":["$","$L17",null,{"items":[]}]}]
0:[["$","$L1",null,{"modelStates":[]}]]
`;

const result = parseRSC(complexPayload);

Error Handling

try {
  const result = parseRSC(malformedPayload);
} catch (error) {
  console.error('Failed to parse RSC:', error);
}

Use Cases

  • Development Tools: Build RSC inspectors and debuggers
  • Testing: Parse and analyze RSC payloads in tests
  • Documentation: Generate documentation from RSC payloads
  • Migration: Convert RSC payloads to other formats
  • Analysis: Analyze component usage and dependencies

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

Related