jsonthink
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

JSONThink

Proposal

Use a generic json to export and import object with multiples types.

Sample

Look at this json file.

{
  "id": "586fedcc-a547-418d-8dff-93b54053655f",
  "date": {
    "$$type": "Date",
    "date": "2021-05-14T16:41:28.090Z"
  },
  "size": {
    "$$type": "BigInt",
    "value": "912384592101238283288242"
  },
  "hashPass": {
    "$$type": "Buffer",
    "data": [49, 50, 51, 52]
  }
}

Now, we to be using jsonThink.parse to parse the file.

// $ node -r jsonThink/register

// This is only to read the input data
const jsonData = fs.readFileSync(jsonfile, "utf8");

jsonThink.parse(jsonData);
// Output:
// {
//   id: '586fedcc-a547-418d-8dff-93b54053655f',
//   date: 2021-05-14T16:41:28.090Z,
//   size: 912384592101238283288242n,
//   hashPass: <Buffer 31 32 33 34>
// }

Package Sidebar

Install

npm i jsonthink

Weekly Downloads

0

Version

0.1.4

License

ISC

Unpacked Size

14.1 kB

Total Files

22

Last publish

Collaborators

  • jondotsoy