https://github.com/wessberg/marshaller
A lightweight way to serialize and deserialize complex data types non-destructively
https://github.com/wessberg/marshaller
demarshall deserialization deserialize marshall marshaller marshalling serialization serialize unmarshall
Last synced: about 1 year ago
JSON representation
A lightweight way to serialize and deserialize complex data types non-destructively
- Host: GitHub
- URL: https://github.com/wessberg/marshaller
- Owner: wessberg
- License: mit
- Created: 2017-04-23T23:08:27.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-02-09T10:29:48.000Z (over 7 years ago)
- Last Synced: 2025-05-24T00:50:25.449Z (about 1 year ago)
- Topics: demarshall, deserialization, deserialize, marshall, marshaller, marshalling, serialization, serialize, unmarshall
- Language: TypeScript
- Homepage:
- Size: 563 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
> A lightweight way to serialize and deserialize complex data types non-destructively
## Description
Marshaller provides a lightweight way to serialize and deserialize complex data types non-destructively.
Essentially, it is `JSON.parse()` and `JSON.stringify` with support for far more data types, circular references, and with the guarantee that
whatever is serialized can be deserialized into the exact same representation without losing _any_ information.
You can consider this to be direct replacements for the `JSON.[stringify|parse]` methods, provided through `marshall` for serialization and `demarshall` for deserialization.
### Features
- _"`JSON.parse`/`JSON.stringify` on steroids"_
- Non-destructive serialization/deserialization of data
- Supports Circular references
- A wide variety of supported data types - from simple things as strings to complex things such as Maps, Sets and Typed Arrays
## Table of Contents
- [Description](#description)
- [Features](#features)
- [Table of Contents](#table-of-contents)
- [Install](#install)
- [NPM](#npm)
- [Yarn](#yarn)
- [Supported data types and features](#supported-data-types-and-features)
- [Usage](#usage)
- [Contributing](#contributing)
- [Maintainers](#maintainers)
- [Backers](#backers)
- [Patreon](#patreon)
- [FAQ](#faq)
- [Why are functions not supported](#why-are-functions-not-supported)
- [License](#license)
## Install
### NPM
```
$ npm install @wessberg/marshaller
```
### Yarn
```
$ yarn add @wessberg/marshaller
```
## Supported data types and features
- Anything that is JSON serializable today: `number`, `boolean`, `string`, `array`, `object literal`
- References, including circular references
- `RegExp`
- `Date`
- `Map`
- `Set`
- `Symbol`
- `BigInt`
- `undefined`
- `null`
- `Int8Array`
- `Int16Array`
- `Int32Array`
- `UInt8Array`
- `UInt8ClampedArray`
- `UInt16Array`
- `UInt32Array`
- `Float32Array`
- `Float64Array`
- `String`
- `Number`
- `Boolean`
## Usage
```typescript
import {marshall, demarshall} from "@wessberg/marshaller";
// Marshall some complex data that wouldn't normally be JSON serializable
const marshallResult = marshall({
a: new Set([1, 2, /foo/, {a: new Date(), b: new Float32Array([1, 2, 3])}])
});
// Demarshall it to get a structurally identical representation back of the data
const demarshallResult = demarshall(marshallResult);
```
## Contributing
Do you want to contribute? Awesome! Please follow [these recommendations](./CONTRIBUTING.md).
## Maintainers
|
|
| --------------------------------------------------------------------------------------------------------------------------------- |
| [Frederik Wessberg](mailto:frederikwessberg@hotmail.com)
[@FredWessberg](https://twitter.com/FredWessberg)
_Lead Developer_ |
## Backers
### Patreon
[Become a backer](https://www.patreon.com/bePatron?u=11315442) and get your name, avatar, and Twitter handle listed here.
## FAQ
#### Why are functions not supported
First, there are security considerations. But more importantly, functions can reference identifiers that lives in a lexical
environment that is declared outside of the local scope of that function. Marshalling this data would require passing in
a sandboxed environment which breaks the promise of the library - simple replacement for JSON, with non-destructive serialization/deserialization.
## License
MIT © [Frederik Wessberg](mailto:frederikwessberg@hotmail.com) ([@FredWessberg](https://twitter.com/FredWessberg)) ([Website](https://github.com/wessberg))
