0.18.0 • Published 11 months ago

@otpjs/serializer-json v0.18.0

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months 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

11 months ago

0.18.0

11 months ago

0.17.3

1 year ago

0.17.4

1 year ago

0.15.6

1 year ago

0.17.5

1 year ago

0.17.6

1 year ago

0.17.7

1 year ago

0.16.0

1 year ago

0.17.0

1 year ago

0.17.1

1 year ago

0.15.0

2 years ago

0.14.0

2 years ago

0.13.4

2 years ago

0.13.5

2 years ago

0.13.0

2 years ago

0.12.1

2 years ago

0.12.2

2 years ago

0.12.3

2 years ago

0.12.6

2 years ago

0.12.0

2 years ago

0.10.0

2 years ago

0.11.0

2 years ago

0.11.1

2 years ago

0.10.0-beta.21

2 years ago

0.10.0-beta.20

2 years ago

0.10.0-beta.19

2 years ago

0.10.0-beta.18

2 years ago

0.10.0-beta.15

2 years ago

0.10.0-beta.13

2 years ago

0.10.0-beta.12

2 years ago

0.10.0-beta.11

2 years ago

0.10.0-beta.10

2 years ago

0.10.0-beta.5

2 years ago

0.10.0-beta.4

2 years ago

0.10.0-beta.2

2 years ago

0.10.0-beta.1

2 years ago

0.10.0-beta.0

2 years ago