pjo

persisted-json-object

make a normal object persist as JSON

Showing:

Popularity

Downloads/wk

2

GitHub Stars

3

Maintenance

Last Commit

9mos ago

Contributors

0

Package

Dependencies

0

Size (min+gzip)

0.5KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Persisted JSON objects for Node

This is an object that functions like a plain JavaScript object, but it saves itself to the file system after every change. Uses Proxy.

Usage

Use it just like a regular JavaScript object:

let jsonObject = require("persisted-json-object");

let obj = jsonObject({ file: "data.json" });

obj.foo = "boo";

obj.temporary = "soon to be deleted";
delete obj.temporary;

obj.grue = "you";

obj.coolNumbers = [420, 666, 69, 12];

After these changes, data.json will look like this (some formatting added):

{
  "foo": "boo",
  "grue": "you",
  "coolNumbers": [420, 666, 69, 12]
}

A few notes:

  • If data.json exists, it will load that data.
  • If data.json doesn't exist, it will be written as soon as you set a property.
  • Errors will be thrown if your object cannot be serialized as JSON.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100