JSPM

  • Created
  • Published
  • Downloads 2371
  • Score
    100M100P100Q102808F
  • License MIT

JSON encoder/decoder for AssemblyScript

Package Exports

  • json-as

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 encoder/decoder for AssemblyScript

Installation

~ npm install json-as
--transform json-as/transform

Support

  • ✅ Objects
  • ✅ Arrays
  • ✅ Numbers
  • ✅ Integers
  • ✅ Null
  • ❌ Dynamic Arrays
  • ❌ Dynamic Types
  • ❌ Dynamic Objects Note: Dynamic types are planned in the near future.

Usage

import { JSON } from 'json-as'

Object

@json
class JSONSchema {
    firstName: string
    lastName: string
    age: i32
}

const data: JSONSchema {
    firstName: 'Jairus',
    lastName: 'Tanaka',
    age: 14
}

const stringified = JSON.stringify(data)
// '{"firstName":"Jairus","lastName":"Tanaka","age":14}'

const parsed = JSON.parse<JSONSchema>(stringified)
// { firstName: "Jairus", lastName: "Tanaka", age: 14 }

Array

const stringified = JSON.stringify(['Hello', 'World'])
// '["Hello","World"]'

const parsed = JSON.parse<JSONSchema>(stringified)
// ["Hello", "World"]

Float

const stringified = JSON.stringify(3.14)
// '3.14'

const parsed = JSON.parse<f64>(stringified)
// 3.14

Integer

const stringified = JSON.stringify(14)
// '14'

const parsed = JSON.parse<i32>(stringified)
// 14

Boolean

const stringified = JSON.stringify(true)
// 'true'

const parsed = JSON.parse<boolean>(stringified)
// true

Bool

const stringified = JSON.stringify(true)
// 'true'

const parsed = JSON.parse<bool>(stringified)
// true

Null

const stringified = JSON.stringify(true)
// 'true'

const parsed = JSON.parse<boolean>(stringified)
// true