Skip to main content

Try it Live

Run RLP examples in the interactive playground

RLP Serialization

Convert RLP data structures to and from JSON for persistence, debugging, and transmission.

Overview

RLP serialization provides JSON conversion for:
  • Persistence - Save RLP structures to databases or files
  • Debugging - Human-readable representation
  • Transmission - Send over JSON APIs
  • Testing - Compare structures in test assertions

toJSON

Convert RLP data to JSON-serializable format.

    JSON Format

    toJSON converts Uint8Array to number arrays while preserving structure:

    fromJSON

    Convert JSON representation back to RLP data.

      Validation

      fromJSON validates structure:

      Round-trip Serialization

      Convert to JSON and back produces equal structures:

      Use Cases

      Database Storage

      Store RLP structures in JSON databases:

      API Transmission

      Send RLP data over HTTP APIs:

      Debugging

      Pretty-print RLP structures:

      Testing

      Compare RLP structures in tests:

      Caching

      Cache RLP structures as JSON:

      Migration

      Convert between RLP versions:

      Performance Considerations

      JSON vs Binary

      JSON serialization is less efficient than binary RLP:
      Use RLP for:
      • Network transmission
      • On-chain storage
      • Binary protocols
      Use JSON for:
      • Debugging
      • APIs where JSON expected
      • Database storage
      • Human interaction

      Tree-shaking

      Import only needed functions: