A pure Go JSON library with SIMD acceleration — drop-in replacement for encoding/json

HVJSON

High Velocity JSON

A blazing-fast, zero-CGO JSON library that outperforms encoding/json while maintaining full API compatibility.

  Pure Go   Zero CGO   Apache 2.0   Drop-in Replacement

Performance Comparison

Operation HVJson encoding/json Improvement
Marshal (pointer) 88.0 ns/op, 0 allocs 121.6 ns/op, 1 alloc 27.6% faster
Marshal (value) 118.5 ns/op 138.2 ns/op 14.2% faster
MarshalTo (zero-copy) 88.4 ns/op, 0 allocs N/A Zero-copy API
Unmarshal 529.4 ns/op 736.5 ns/op 28.1% faster
Streaming encoder 195.0 ns/op N/A Single write

API Surface

Core API

  • Marshal / MarshalString
  • MarshalTo (zero-copy)
  • MarshalPooled (buffer reuse)
  • MarshalIndent (pretty print)
  • FastMarshal (pre-compiled)

Decoding

  • Unmarshal / UnmarshalString
  • UnmarshalWithConfig
  • Number type for exact representation
  • Strict field validation
  • Custom type support

Streaming Encoding

  • NewEncoder (single write)
  • IncrementalStreamEncoder
  • Bounded memory (64KB flush)
  • NDJSON support
  • io.Writer compatible

Streaming Write API

  • WriteObjectStart / WriteObjectEnd
  • WriteArrayStart / WriteArrayEnd
  • WriteString, WriteInt64, WriteFloat64
  • WriteBool, WriteNull
  • Max 64 nesting depth

Streaming Decoding

  • NewDecoder with More() / Buffered()
  • DisallowUnknownFields
  • UseNumber / UseInt64
  • SIMD whitespace skipping
  • Token-based iteration

Configuration

  • UTF-8 validation toggle
  • Streaming validation (>1MB)
  • Max depth (10,000 default)
  • HTML escaping control
  • Struct field caching

SIMD Accelerations

  HasSpecialChars: 5-8x faster character scanning
  EscapeJSONString: 3-5x faster string escaping
  FormatInt64 / FormatUint64: 2-3x faster integer formatting
  FormatFloat64: 2-4x faster float formatting
  SkipWhitespace: critical for 20-40% of JSON processing time
  ValidateUTF8: 10-20x faster for ASCII-heavy content

Optimization Internals

  Pre-compiled type encoders (eliminate runtime reflection)
  Pre-encoded field names with quotes
  Integer lookup table (0-9999)
  Pre-computed indent tables (2-space, 4-space, tab for 0-16 levels)
  3-tier buffer pool (1KB, 64KB, 1MB)
  Struct field caching (thread-safe)
  Inline cycle detection (8-pointer array)
  Comprehensive error types with line/column/position tracking

Accelerate Your JSON Processing

Drop-in replacement. Zero CGO. Pure performance.

View on GitHub Documentation