šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Book a DemoInstallSign in
Socket

json-as

Package Overview
Dependencies
Maintainers
0
Versions
192
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-as

The only JSON library you'll need for AssemblyScript. SIMD enabled

1.0.0-beta.2
Source
npm
Version published
Weekly downloads
1.6K
-16.94%
Maintainers
0
Weekly downloads
Ā 
Created
Source
     ā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ  ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ  ā–ˆā–ˆā–ˆ    ā–ˆā–ˆ        ā–ˆā–ˆā–ˆā–ˆā–ˆ  ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ
     ā–ˆā–ˆ ā–ˆā–ˆ      ā–ˆā–ˆ    ā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆ   ā–ˆā–ˆ       ā–ˆā–ˆ   ā–ˆā–ˆ ā–ˆā–ˆ     
     ā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ ā–ˆā–ˆ    ā–ˆā–ˆ ā–ˆā–ˆ ā–ˆā–ˆ  ā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ
ā–ˆā–ˆ   ā–ˆā–ˆ      ā–ˆā–ˆ ā–ˆā–ˆ    ā–ˆā–ˆ ā–ˆā–ˆ  ā–ˆā–ˆ ā–ˆā–ˆ       ā–ˆā–ˆ   ā–ˆā–ˆ      ā–ˆā–ˆ
 ā–ˆā–ˆā–ˆā–ˆā–ˆ  ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ  ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ  ā–ˆā–ˆ   ā–ˆā–ˆā–ˆā–ˆ       ā–ˆā–ˆ   ā–ˆā–ˆ ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆ
 
    AssemblyScript - v1.0.0-beta.2
  

šŸ“š Contents

  • About
  • Installation
  • Usage
  • Examples
  • Performance
  • License
  • Contact

šŸ“ About

JSON is the de-facto serialization format of modern web applications, but its serialization and deserialization remain a significant performance bottleneck, especially at scale. Traditional parsing approaches are computationally expensive, adding unnecessary overhead to both clients and servers. This library is designed to mitigate this by leveraging SIMD acceleration and highly optimized transformations.

šŸ’¾ Installation

npm install json-as@1.0.0-beta.2

Add the --transform to your asc command (e.g. in package.json)

--transform json-as/transform

Alternatively, add it to your asconfig.json

{
  // ...
  "options": {"transform": ["json-as/transform"]}
}

If you'd like to see the code that the transform generates, run with JSON_DEBUG=true

šŸŖ„ Usage

import { JSON } from "json-as";

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

@json
class Player {
  @alias("first name")
  firstName!: string;
  lastName!: string;
  lastActive!: i32[];
  // Drop in a code block, function, or expression that evaluates to a boolean
  @omitif((self: Player) => self.age < 18)
  age!: i32;
  @omitnull()
  pos!: Vec3 | null;
  isVerified!: boolean;
}

const player: Player = {
  firstName: "Jairus",
  lastName: "Tanaka",
  lastActive: [2, 13, 2025],
  age: 18,
  pos: {
    x: 3.4,
    y: 1.2,
    z: 8.3
  },
  isVerified: true
};

const serialized = JSON.stringify<Player>(player);
const deserialized = JSON.parse<Player>(serialized);

console.log("Serialized    " + serialized);
console.log("Deserialized  " + JSON.stringify(deserialized));

Examples

⚔ Performance

The json-as library has been optimized to achieve near-gigabyte-per-second JSON processing speeds through SIMD acceleration and highly efficient transformations. Below are some key performance benchmarks to give you an idea of how it performs.

Raw Performance

Simple

Test CaseSerialization (ops/s)Deserialization (ops/s)Serialization (MB/s)Deserialization (MB/s)
Vector3 Object32,642,320 ops/s9,736,272 ops/s1,240 MB/s369 MB/s
Alphabet String4,928,856 ops/s7,567,360 ops/s975 MB/s1,498 MB/s
Small JSON Object[Fill Value][Fill Value][Fill Value][Fill Value]
Medium JSON Object[Fill Value][Fill Value][Fill Value][Fill Value]
Large JSON Object[Fill Value][Fill Value][Fill Value][Fill Value]

SIMD

Test CaseSerialization (ops/s)Deserialization (ops/s)Serialization (MB/s)Deserialization (MB/s)
Vector3 Object32,642,320 ops/s9,736,272 ops/s1,240 MB/s369 MB/s
Alphabet String20,368,584 ops/s28,467,424 ops/s3,910 MB/s5,636 MB/s
Small JSON Object[Fill Value][Fill Value][Fill Value][Fill Value]
Medium JSON Object[Fill Value][Fill Value][Fill Value][Fill Value]
Large JSON Object[Fill Value][Fill Value][Fill Value][Fill Value]

JavaScript

Test CaseSerialization (ops/s)Deserialization (ops/s)Serialization (MB/s)Deserialization (MB/s)
Vector3 Object2,548,013 ops/s1,942,440 ops/s97 MB/s73 MB/s
Alphabet String3,221,556 ops/s2,716,617 ops/s624 MB/s537 MB/s
Small JSON Object[Fill Value][Fill Value][Fill Value][Fill Value]
Medium JSON Object[Fill Value][Fill Value][Fill Value][Fill Value]
Large JSON Object[Fill Value][Fill Value][Fill Value][Fill Value]

Real-World Usage

ScenarioJSON Size (kb)Serialization Time (ops/s)Deserialization Time (ops/s)Throughput (GB/s)
Web API Response[Fill Value][Fill Value][Fill Value][Fill Value]
Database Entry[Fill Value][Fill Value][Fill Value][Fill Value]
File Parsing[Fill Value][Fill Value][Fill Value][Fill Value]

šŸ“ƒ License

This project is distributed under an open source license. You can view the full license using the following link: License

šŸ“« Contact

Please send all issues to GitHub Issues and to converse, please send me an email at me@jairus.dev

Keywords

assemblyscript

FAQs

Package last updated on 25 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts