Skip to content

json-as 2.1 ​

Type-safe JSON for AssemblyScript, compiled for your models.

Mark a class with @json, enable the compiler transform, and use JSON.parse<T> and JSON.stringify. The transform generates readers and writers at build time; your application needs no runtime schema or reflection.

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

@json
class Point {
  x: f32 = 0;
  y: f32 = 0;
  label: string = "";
}

function readX(input: string): f32 {
  const point = JSON.parse<Point>(input);
  return point.x;
}

Lazy parsing is enabled by default in 2.1. Visible parse sites can skip decoding fields proven unused. Here, the reader can scan past y and label while decoding x. Full reads and uncertain uses retain eager behavior. This optimization creates no lazy getters or saved source ranges for ordinary fields.

Version

These docs cover 2.1.0. For installation before its npm publication, use the packed-source instructions. The upgrade guide covers the changes from 2.0.

Start here ​

Reference ​

Implementation ​

Upgrading from 1.x? Read the 2.0 migration notes too.

GitHub · npm · MPL-2.0 license