🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →

json-as

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-as - npm Package Compare versions

Comparing version

to
0.5.9

@@ -121,2 +121,5 @@ import { u128, u128Safe, u256, u256Safe, i128, i128Safe, i256Safe } from "as-bignum/assembly";

return parseBigNum<T>(data);
} else if (type instanceof Date) {
// @ts-ignore
return Date.fromString(data);
} else {

@@ -123,0 +126,0 @@ // @ts-ignore

import { wasi_console } from "@assemblyscript/wasi-shim/assembly/wasi_console";
import { u128 } from "as-bignum/assembly";
import {
JSON
} from ".";
@json
class Player {
firstName: string;
lastName: string;
lastActive: i32[];
age: i32;
pos: Vec3 | null;
isVerified: boolean;
stats: Stats
}
@json
class Contacts {
type: string
player: string
}
const player = JSON.createObjectUnsafe<Player>()
player.firstName = "John";
player.lastName = "West";
player.age = 23;
const contact: Contacts = {
player: JSON.stringify(player),
type: "friends"
}
let stringifiedContact = JSON.stringify(contact);
console.log("Input (Should see backslashes logged): " + stringifiedContact);
const contacts = JSON.parse<Contacts>(stringifiedContact)
console.log("Player: " + contacts.player);
console.log("Type: " + contacts.type);
const parsedPlayer = JSON.parse<Player>(contacts.player);
console.log("Final Player: " + JSON.stringify(parsedPlayer));
console.log("Final Result (Contacts): " + JSON.stringify(contacts));/*
/*
// @ts-ignore
@json
class Stats {
wins: u128
loss: u128
}*/
wins!: u128
loss!: u128
}
// @ts-ignore
@json
class Vec3 {
x: f32;
y: f32;
z: f32;
x!: f32;
y!: f32;
z!: f32;
}
// @ts-ignore
@json
class Test {
data: string
}
const vec: Vec3 = {

@@ -65,16 +26,14 @@ x: 3.4,

}
const test: Test = {
data: JSON.stringify(vec)
}
/*
// @ts-ignore
@json
class Player {
firstName: string;
lastName: string;
lastActive: i32[];
age: i32;
pos: Vec3 | null;
isVerified: boolean;
stats: Stats
firstName!: string;
lastName!: string;
lastActive!: i32[];
createdAt!: Date;
age!: i32;
pos!: Vec3 | null;
isVerified!: boolean;
stats!: Stats
}

@@ -86,2 +45,3 @@

lastActive: [8, 27, 2022],
createdAt: Date.fromString("2021-12-08T00:59:26.230Z"),
age: 23,

@@ -99,8 +59,6 @@ pos: {

};
*//*
const serializedPlayer = JSON.stringify<Test>(test);
const serializedPlayer = JSON.stringify<Player>(player);
wasi_console.log("Serialized Player: " + serializedPlayer);
const deserializedPlayer = JSON.parse<Test>(serializedPlayer);
const deserializedPlayer = JSON.parse<Player>(serializedPlayer);
wasi_console.log("Deserialized Player: " + JSON.stringify(deserializedPlayer));
wasi_console.log("Deserialize Vec3: " + JSON.stringify(JSON.parse<Vec3>(deserializedPlayer.data)))
*/
{
"name": "json-as",
"version": "0.5.8",
"version": "0.5.9",
"description": "JSON encoder/decoder for AssemblyScript",

@@ -19,8 +19,3 @@ "types": "assembly/index.ts",

"test:wasm3": "wasm3 ./build/test.wasm",
"prettier": "as-prettier -w .",
"asbuild:debug": "asc assembly/index.ts --target debug",
"asbuild:release": "asc assembly/index.ts --target release",
"asbuild": "yarn asbuild:debug && yarn asbuild:release",
"test": "node tests",
"start": "npx serve ."
"prettier": "as-prettier -w ."
},

@@ -58,9 +53,3 @@ "devDependencies": {

"homepage": "https://github.com/JairusSW/as-json#readme",
"type": "module",
"exports": {
".": {
"import": "./build/release.js",
"types": "./build/release.d.ts"
}
}
"type": "module"
}

@@ -30,3 +30,3 @@ # AS-JSON

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

@@ -40,12 +40,5 @@ }

import { JSON } from "json-as/assembly";
import { u128 } from "as-bignum/assembly";
// @ts-ignore
@json
class Stats {
wins: u128
loss: u128
}
// @ts-ignore
@json
class Vec3 {

@@ -66,3 +59,2 @@ x: f32;

isVerified: boolean;
stats: Stats
}

@@ -80,10 +72,6 @@

},
isVerified: true,
stats: {
wins: u128.fromString("443"),
loss: u128.fromString("693")
}
isVerified: true
};
const stringified = JSON.stringify<Player>(data);
const stringified = JSON.stringify<Player>(player);

@@ -96,13 +84,21 @@ const parsed = JSON.parse<Player>(stringified);

**Does it support the JSON specification?**
Yes, it does. However, dynamic objects and arrays are not supported, but planned in the near future.
**Is it fast?**
Look below
**How does it compare to other librarys?**
**How does it compare to other libs?**
Its pretty much the same as the other libraries out there (near/assemblyscript-json and @serial-as/json), but it focuses highly on performance
**Will it catch invalid JSON?**
No, it does not check for invalid JSON, but gives its best shot at parsing instead. Will probably throw an error.
**How does it compare performance-wise to other libraries?**
In my testing, parsing a Vector 2 runs at 2.2m ops/s with as-json and around 10,000 ops/s with assemblyscript-json and @serial-as/json.
Both are great libraries however.
## Performance

@@ -109,0 +105,0 @@

{
"name": "@json-as/transform",
"version": "0.5.8",
"version": "0.5.9",
"description": "JSON encoder/decoder for AssemblyScript",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",