Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/swlws/json-ify

javascript object serialization
https://github.com/swlws/json-ify

Last synced: about 1 month ago
JSON representation

javascript object serialization

Awesome Lists containing this project

README

        

# JSONify

a json serialization lib, supported data type:

- number
- string
- boolean
- date
- regexp
- function, arrow function
- map
- set

# usage

```ts
import { stringify, parse } from "@swl/json-ify";

const obj = {
a: null,
b: undefined,
c: 100,
d: "dd",
e: true,
f: {},
g: [],
h: new Date(),
i: new Set([11, 22, 33, new Set([55, 66, 77])]),
j: new Map([
["age", { age: 100 }],
[{ age: 100 }, "age"],
]),
k: function () {
return this.a;
},
l: () => {
return "arrow function";
},
m: /abc/g,
n: new RegExp("abc", "img"),
};

const rt = stringify(obj, 2);
console.log(rt);
const rt2 = parse(rt);
console.log(rt2);
```