npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@klave/as-json

v0.5.67-fix.0

Published

JSON encoder/decoder for AssemblyScript

Downloads

207

Readme

Installation

npm install json-as

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"]
  }
}

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);
// Alternative: use JSON.serializeTo(player, out);

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

If you use this project in your codebase, consider dropping a star. I would really appreciate it!

Performance

Run or view the benchmarks here

Below are benchmark results comparing JavaScript, WAVM (WebAssembly Virtual Machine), and Wasmtime environments.

JavaScript Results

NodeJS v20.5.1 - TinyBench v2.5.0 (V8)

┌───────────────────────────┬───────────────┐
│         Task Name         │   ops / sec   │
├───────────────────────────┼───────────────┤
│ 'Stringify Object (Vec3)' │  '1,191,221'  │
│   'Parse Object (Vec3)'   │  '897,759'    │
│ 'Stringify Number Array'  │  '1,552,255'  │
│   'Parse Number Array'    │  '1,225,325'  │
│    'Stringify String'     │  '1,761,011'  │
│      'Parse String'       │  '80,845'     │
└───────────────────────────┴───────────────┘

AssemblyScript Results

WAVM v0.0.0-prerelease - as-bench v0.0.0-alpha (LLVM)

┌───────────────────────────┬───────────────┐
│         Task Name         │   ops / sec   │
├───────────────────────────┼───────────────┤
│ 'Stringify Object (Vec3)' │  '6,270,322'  │
│   'Parse Object (Vec3)'   │  '8,000,195'  |
│ 'Stringify Number Array'  │  '6,664,937'  │
│   'Parse Number Array'    │  '6,557,357'  │
│    'Stringify String'     │  '6,946,947'  │
│      'Parse String'       │  '10,952,502' │
└───────────────────────────┴───────────────┘

Wasmtime v11.0.1 - as-bench v0.0.0-alpha (Cranelift)

┌───────────────────────────┬───────────────┐
│         Task Name         │   ops / sec   │
├───────────────────────────┼───────────────┤
│ 'Stringify Object (Vec3)' │  '2,038,684'  │
│   'Parse Object (Vec3)'   │  '4,623,337'  |
│ 'Stringify Number Array'  │  '2,500,947'  │
│   'Parse Number Array'    │  '2,959,180'  │
│    'Stringify String'     │  '3,236,896'  │
│      'Parse String'       │  '5,634,594'  │
└───────────────────────────┴───────────────┘

Issues

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