Skip to content

json-as

Fast, type-safe JSON for AssemblyScript.

GitHub · npmnpm install json-as

json-as is a compiler transform: mark a class @json and it generates specialized serialize/deserialize code at build time. No runtime reflection, no hand-written schemas — just JSON.parse<T> and JSON.stringify, reaching multi-GB/s throughput with SIMD/SWAR scanning.

ts
import { JSON } from "json-as";

@json
class Vec3 {
  x: f32 = 0;
  y: f32 = 0;
  z: f32 = 0;
}

const v = JSON.parse<Vec3>('{"x":1.5,"y":2.5,"z":3.5}');
JSON.stringify(v); // '{"x":1.5,"y":2.5,"z":3.5}'

Highlights

  • TypedJSON.parse<T> / JSON.stringify over your own @json classes, nested to any depth.
  • Batteries included — strings, all number types, bool, Date, arrays, Map, Set, typed arrays, ArrayBuffer.
  • Dynamic when you need itJSON.Value, JSON.Obj, and JSON.Raw for unknown or open-ended shapes.
  • Lazy fields — defer parsing of fields you rarely read; untouched fields pass through their raw bytes on serialize.
  • Custom formats@serializer / @deserializer for compact or bespoke wire formats.
  • Fast — three interchangeable scanning modes (SWAR, SIMD, NAIVE) selected at build time.

Guide

Reference

Deep Dive

How the interesting parts actually work:

Testing your AssemblyScript too? See as-test.