🚀 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
1
Versions
194
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-as

JSON encoder/decoder for AssemblyScript

0.5.31
Source
npm
Version published
Weekly downloads
2.8K
6.39%
Maintainers
1
Weekly downloads
 
Created
Source

AS-JSON

AssemblyScript WebAssembly

Probably the fastest JSON implementation for AssemblyScript with many more optimizations coming down the pipeline.

Installation

npm install json-as
npm install visitor-as --save-dev

For arbitrary-length numbers, use

npm install as-bignum

Add the transform to your asc command

--transform json-as/transform

Or, add it to asconfig.json

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

Usage

import { JSON } from "json-as/assembly";

// @json or @serializable work here
@json
class Vec3 {
  x!: f32;
  y!: f32;
  z!: f32;
}

@json
class Player {
  firstName!: string;
  lastName!: string;
  lastActive!: i32[];
  age!: i32;
  pos!: Vec3 | null;
  isVerified!: boolean;
}

const player: Player = {
  firstName: "Emmet",
  lastName: "West",
  lastActive: [8, 27, 2022],
  age: 23,
  pos: {
    x: 3.4,
    y: 1.2,
    z: 8.3
  },
  isVerified: true
};

const stringified = JSON.stringify<Player>(player);

const parsed = JSON.parse<Player>(stringified);

Notes

Performance exceeds JavaScript JSON implementation by an average of 230% but this decreases with larger data packets.

Planned Features

  • Serialize
    • Objects
    • Other Types
    • Dynamic Types
  • Deserialize
    • Objects
    • Other Types
    • Dynamic Types
  • Streaming API
  • Whitespace support
  • Integrate features from SIMDJson
  • Optimize
    • Strings
    • Int/Float
    • Bool
    • Object Serialization
    • Object Parsing
    • Arrays

Performance

Serialize Object (Vec3): ~11.1m ops/s

Deserialize Object (Vec3): ~3.2m ops/s

Serialize Array (int[]): ~1.4m ops/s

Deserialize Array (int[]): ~2.8m ops/s

Serialize String (5): ~4.2m ops/s

Deserialize String (5): ~12m ops/s

Issues

Please submit an issue to https://github.com/JairusSW/as-json/issues if you find anything wrong with this library

Keywords

assemblyscript

FAQs

Package last updated on 05 Mar 2023

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