Socket
Book a DemoInstallSign in
Socket

telejson

Package Overview
Dependencies
Maintainers
5
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

telejson

A library for teleporting rich data to another place.

8.0.0
latest
Source
npmnpm
Version published
Weekly downloads
3.5M
-17.98%
Maintainers
5
Weekly downloads
 
Created

What is telejson?

The telejson npm package is designed for efficient serialization and deserialization of JavaScript objects, including those with complex types that are not natively supported by JSON, such as Date objects, RegExp, and functions. It is particularly useful for scenarios where you need to transmit complex objects over a network or store them in a way that preserves their type information.

What are telejson's main functionalities?

Serialization of complex types

This feature allows the serialization of complex JavaScript types into a string. The code sample demonstrates how to serialize an object containing a Date and a RegExp, which are not natively supported by JSON.

const { stringify } = require('telejson');
const obj = { date: new Date(), regex: /test/i };
const serialized = stringify(obj);

Deserialization with type restoration

This feature enables the deserialization of a string back into a JavaScript object, with the restoration of complex types. The code sample shows how to deserialize a string containing serialized Date and RegExp objects, restoring them to their original types.

const { parse } = require('telejson');
const serialized = '{"date":"2023-04-01T00:00:00.000Z","regex":"/test/i"}';
const obj = parse(serialized);

Function serialization and deserialization

Telejson can serialize and deserialize functions, which is not supported by standard JSON. The code sample demonstrates serializing an object containing a function and then deserializing it, preserving the function.

const { stringify, parse } = require('telejson');
const obj = { func: function add(a, b) { return a + b; } };
const serialized = stringify(obj);
const deserialized = parse(serialized);

Other packages similar to telejson

Keywords

JSON

FAQs

Package last updated on 16 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.