0.18.0 • Published 2 years ago

@otpjs/serializer-json v0.18.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Open Telecom Platform on JS

JSON Serialization

This module provides extended JSON serialization/deserialization functionality.

Installation

npm i @otpjs/serializer-json

Usage

Initializing

In order to be able to properly serialize/deserialize Pids and Refs, you must initialize @otpjs/serializer-json with an instance of Node from @otpjs/core.

import { Node } from '@otpjs/core';
import makeJSON from '@otpjs/serializer-json';

const node = new Node();
const JSON = makeJSON(node);

serialize/encode

Encodes a JavaScript value as an Erlang term stored in a Buffer. Understands types from @otpjs/types as well.

import { t, l } from '@otpjs/types';

// When serializing complex types, "tags" the output
JSON.serialize(t(1, 2, 3)); // ["$otp.tuple", [1, 2, 3]]
JSON.serialize(l(1, 2, 3)); // ["$otp.list", [1, 2, 3], "$otp.list.nil"]
JSON.serialize(Pid.of(0, 1, 2, 3)); // ["$otp.pid", ["$otp.symbol", "otp-0@127.0.0.1"], 1, 2, 3]

deserialize/parse

Decodes a String containing a JSON-encoded value into native types. Resaturates complex types when encountered in the JSON structure.

import { t, l } from '@otpjs/types';

JSON.deserialize(['$otp.list', [1, 2, 3], '$otp.list.nil']); // [1, 2, 3]
JSON.deserialize(['$otp.pid', ['$otp.symbol', 'otp-0@127.0.0.1'], 1, 2, 3]); // Pid<0.1.2>

Complex Type Support

Current limited support for complex Javascript types to the types published in @otpjs/types, including Tuple and List.

Support for maps (raw Object and Map instances) is forthcoming. Seeking input on how to treat Array: is it a tuple or a list? Neither is a perfect fit.

0.17.8

2 years ago

0.18.0

2 years ago

0.17.3

3 years ago

0.17.4

3 years ago

0.15.6

3 years ago

0.17.5

3 years ago

0.17.6

3 years ago

0.17.7

3 years ago

0.16.0

3 years ago

0.17.0

3 years ago

0.17.1

3 years ago

0.15.0

3 years ago

0.14.0

3 years ago

0.13.4

3 years ago

0.13.5

3 years ago

0.13.0

3 years ago

0.12.1

3 years ago

0.12.2

3 years ago

0.12.3

3 years ago

0.12.6

3 years ago

0.12.0

3 years ago

0.10.0

3 years ago

0.11.0

3 years ago

0.11.1

3 years ago

0.10.0-beta.21

3 years ago

0.10.0-beta.20

3 years ago

0.10.0-beta.19

3 years ago

0.10.0-beta.18

3 years ago

0.10.0-beta.15

3 years ago

0.10.0-beta.13

3 years ago

0.10.0-beta.12

3 years ago

0.10.0-beta.11

3 years ago

0.10.0-beta.10

3 years ago

0.10.0-beta.5

3 years ago

0.10.0-beta.4

3 years ago

0.10.0-beta.2

3 years ago

0.10.0-beta.1

3 years ago

0.10.0-beta.0

3 years ago