Comparing version
{ | ||
"name": "json-as", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "JSON encoder/decoder for AssemblyScript", | ||
@@ -25,3 +25,3 @@ "types": "assembly/json.ts", | ||
"@serial-as/json": "^1.0.2", | ||
"@types/jest": "^26.0.24", | ||
"@types/jest": "^27.0.2", | ||
"@types/line-column": "^1.0.0", | ||
@@ -38,3 +38,3 @@ "as-base64": "^0.2.0", | ||
"jest": "^27.0.6", | ||
"kati": "^0.5.1", | ||
"kati": "^0.6.1", | ||
"lerna": "^4.0.0", | ||
@@ -46,3 +46,5 @@ "rimraf": "^3.0.2", | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
"@assemblyscript/loader": "^0.19.17" | ||
}, | ||
"repository": { | ||
@@ -62,2 +64,2 @@ "type": "git", | ||
"homepage": "https://github.com/aspkg/as-json#readme" | ||
} | ||
} |
@@ -27,3 +27,3 @@ # AS-JSON | ||
```js | ||
import { JSON, unknown } from 'json-as' | ||
import { JSON } from 'json-as' | ||
``` | ||
@@ -53,3 +53,3 @@ | ||
**Array (Typed)** | ||
**Array** | ||
@@ -64,12 +64,2 @@ ```js | ||
**Array (Dynamic)** | ||
```js | ||
const stringified = JSON.stringify(["Welcome to dynamic arrays", 3.14, ["Deep"], true, "It also supports nulls", null]) | ||
// '["Welcome to dynamic arrays",3.14,["Deep"],true,"It also supports nulls",null]' | ||
const parsed = JSON.parse<unknown[]>(stringified) | ||
// ["Welcome to dynamic arrays", 3.14, ["Deep"], true, "It also supports nulls", null] | ||
``` | ||
**Float** | ||
@@ -124,32 +114,17 @@ | ||
``` | ||
## Accessing unknown types | ||
**Breaking changes for v2.0.0!** | ||
**Experimental usage only** | ||
```js | ||
const parsed = JSON.parse<unknown[]>(["Welcome to dynamic arrays",3.14,["Deep"],true,"It also supports nulls",null]) | ||
console.log(parsed[0].get<string>()) | ||
// "Welcome to dynamic arrays" | ||
console.log(parsed[1].get<f64>().toString()) | ||
// 3.14 | ||
``` | ||
## Benchmarks | ||
``` | ||
AS-JSON Stringify String: ~1858051.4 ops/s | 53.82ms | ||
AS-JSON Parse String: ~4321632.43 ops/s | 23.14ms | ||
AS-JSON Stringify Integer: ~8529956.89 ops/s | 11.72ms | ||
AS-JSON Parse Integer: ~27839325.77 ops/s | 3.59ms | ||
AS-JSON Stringify Float: ~5128590.39 ops/s | 19.5ms | ||
AS-JSON Parse Float: ~21467505.24 ops/s | 4.66ms | ||
AS-JSON Stringify Boolean: ~361837455.83 ops/s | 0.28ms | ||
AS-JSON Parse Boolean: ~51522012.58 ops/s | 1.94ms | ||
AS-JSON Stringify Array: ~1421792.72 ops/s | 70.33ms | ||
AS-JSON Parse Array: ~3755593.05 ops/s | 26.63ms | ||
AS-JSON Stringify Object: ~3309471.1 ops/s | 30.22ms | ||
AS-JSON Parse Object: ~1054387.45 ops/s | 94.84ms | ||
AS-JSON Stringify Dynamic Array: ~285433.75 ops/s | 350.34ms | ||
AS-JSON Parse Dynamic Array: ~661516.87 ops/s | 151.17ms | ||
AS-JSON Stringify String: ~4191267.51 ops/s | 23.86ms | ||
AS-JSON Parse String: ~6218119.99 ops/s | 16.08ms | ||
AS-JSON Stringify Integer: ~13775012.61 ops/s | 7.26ms | ||
AS-JSON Parse Integer: ~55061164.13 ops/s | 1.82ms | ||
AS-JSON Stringify Float: ~7739399.89 ops/s | 12.92ms | ||
AS-JSON Parse Float: ~37522902.16 ops/s | 2.67ms | ||
AS-JSON Stringify Boolean: ~615015015.02 ops/s | 0.16ms | ||
AS-JSON Parse Boolean: ~93901879.87 ops/s | 1.06ms | ||
AS-JSON Stringify Array: ~2380329.74 ops/s | 42.01ms | ||
AS-JSON Parse Array: ~6258786.14 ops/s | 15.98ms | ||
AS-JSON Stringify Object: ~5245632.91 ops/s | 19.06ms | ||
AS-JSON Parse Object: ~1328576.06 ops/s | 75.27ms | ||
``` |
2
-50%71717
-1.92%1
Infinity%14
-12.5%1821
-0.71%126
-16.56%+ Added