Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (json-as) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
AS-JSON
JSON serializer/deserializer for AssemblyScript
Installation
~ npm install json-as
~ yarn add json-as
~ bun install json-as
Add the transform to your asc
command
--transform json-as/transform
Or, add it to asconfig.json
{
"options": {
"transform": "json-as/transform"
}
}
Support
- ✅ Objects (Supported)
- ✅ Arrays (Supported)
- ✅ Numbers (Supported)
- ✅ Integers (Supported)
- ✅ Null (Supported)
- ❌ Dynamic Variants (Not supported)
Usage
import { JSON } from "json-as";
@json
class Vec2 {
x: f32
y: f32
}
@json
class Player {
firstName: string
lastName: string
lastActive: i32[]
age: i32
pos: Vec2
}
const data: Player = {
firstName: "Emmet",
lastName: "West",
lastActive: [8, 27, 2022],
age: 23,
pos: {
x: -3.4,
y: 1.2
}
}
const stringified = JSON.stringify<Player>(data);
// '{"firstName":"Emmet","lastName":"West","lastActive":[8,27,2022],"age":23}'
console.log(`Stringified: ${stringified}`);
const parsed = JSON.parse<Player>(stringified)
// { firstName: "Emmet", lastName: "West", "lastActive": [8,27,2022], age: 23 }
console.log(`Parsed: ${JSON.stringify(parsed)}`)
Issues
Please submit an issue to https://github.com/JairusSW/as-json/issues if you find anything wrong with this library