npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

json-faster

v2.0.0

Published

read write to json object fast using a flat structure read write update.

Readme

json-faster

fast read write to json object using a flat json structure read write update. this package supports the fast, secure and private, memory leak resistant redis like key value json based data store keyvalue-jsondb package.

Example Usage:


const JsonManager = require('json-faster').JsonManager; // Replace with the path to your implementation

// Usage Example:
const manager = new JsonManager();
manager.init({
    12: 20000,
    879898: ["test", "for", "alues"],
    "testing": "for alues",
    "123tsj": "testing",
    "store": ["vaue", "loads", 10],
    'user_id': 101,
    'username': 'alpha_user',
    'status': 'Active',
    'tags': ['premium', 'new_member', 'verified'],
    'location': 'New York City',
    'last_login': '2025-11-10',
    'settings': { theme: 'dark', notifications: true },
    'scores': [95, 88, 92]
})

// Find the entry where the key is 'status' OR the value is 'Active'
const exactMatchResult = manager.searchKeyValue('Active');

console.log('1. Exact Match Result (Active):', exactMatchResult);

manager.write('key1', 'value1');
manager.write('key2', 'value2');

manager.dump()

manager.dumpKeys(['key1', 'key3', 'anotherKey'], { like: true }, "search")

manager.search('^key\\d$', { regex: true })

manager.write('key1', 'value1');
console.log(manager.hasKey('key1')); // true
console.log(manager.getKey('key1')); // 'value1'

USAGE:

Explanation of Each Function Usage:

init(obj):

Initializes the JSON manager with the provided object.

(init or clear data, inits or clears with a blank object)

manager.init({});

manager.init();

write(key, value):

Adds or updates a key-value pair in the JSON object.

(Adding data)

manager.write('key1', 'value1');

manager.write('key2', 'value2');

manager.write('anotherKey', 'value3');

manager.write('keyWithValue1', 'value1');

read(key, options):

Reads the value of a key. If the key doesn't exist and createKey is true, it creates the key with a null value.

(Reading key)

console.log(manager.read('key1', false)); // undefined

console.log(manager.read('key1', true)); // null

hasKey(key):

Checks if a key exists in the JSON object.

console.log(manager.hasKey('key1')); // true

getKey(key):

Retrieves the value of a specific key.

console.log(manager.getKey('key1')); // 'value1'

deleteKey(key):

Deletes a key from the JSON object.

(Delete keys)

manager.deleteKey('key2');

update(obj):

Merges the provided object into the existing JSON object.

manager.update('key2', 'value3');

search(criteria, options):

Searches for keys matching the criteria. Supports exact match, partial match (like), and regex.

(Search for specific keys in an array)

console.log(manager.search(['key1', 'key3', 'anotherKey']));

// Output: [{ key: 'key1', value: 'value1' }, { key: 'anotherKey', value: 'value3' }]

(Search using partial match)

console.log(manager.search('key', { like: true }));

// Output: [{ key: 'key1', value: 'value1' }, { key: 'key2', value: 'value2' }]

(Search using regex)

console.log(manager.search('^key\\d$', { regex: true }));

// Output: [{ key: 'key1', value: 'value1' }, { key: 'key2', value: 'value2' }]

searchValue(criteria, options):

Searches for values matching the criteria. Supports exact match, partial match (like), and regex.

(Searching for values)

console.log(manager.searchValue('value1'));

// Output: [{ key: 'key1', value: 'value1' }, { key: 'keyWithValue1', value: 'value1' }]

console.log(manager.searchValue(['value1', 'value3']));

// Output: [{ key: 'key1', value: 'value1' }, { key: 'keyWithValue1', value: 'value1' }, { key: 'anotherKey', value: 'value3' }]

console.log(manager.searchValue('value', { like: true }));

// Output: [{ key: 'key1', value: 'value1' }, { key: 'key2', value: 'value2' }, { key: 'keyWithValue1', value: 'value1' }, { key: 'anotherKey', value: 'value3' }]

console.log(manager.searchValue('^value\\d$', { regex: true }));

// Output: [{ key: 'key1', value: 'value1' }, { key: 'key2', value: 'value2' }, { key: 'keyWithValue1', value: 'value1' }]

searchKeyValue(criteria, options):

Searches for both keys and values matching the criteria.

(Searching for key-value pairs)

console.log(manager.searchKeyValue('key1'));

// Output: [{ key: 'key1', value: 'value1' }]

console.log(manager.searchKeyValue(['key1', 'value3']));

// Output: [{ key: 'key1', value: 'value1' }, { key: 'anotherKey', value: 'value3' }]

console.log(manager.searchKeyValue('value1', { like: true }));

// Output: [{ key: 'key1', value: 'value1' }, { key: 'keyWithValue1', value: 'value1' }]

console.log(manager.searchKeyValue('^key\\d$', { regex: true }));

// Output: [{ key: 'key1', value: 'value1' }, { key: 'key2', value: 'value2' }]

console.log(manager.searchKeyValue('value2', { regex: true }));

// Output: [{ key: 'key2', value: 'value2' }]

dump():

Returns the entire JSON object.

(Dumping data)

console.log(manager.dump()); // { key1: 'value1' }

dumpKeys(criteria, options, type):

Dumps keys matching the criteria. The type can be "search", "value", or "keyvalue".

(Dumping data based on criteria)

console.log(manager.dumpKeys(['key1', 'key3', 'anotherKey'], { like: true }, "search"));

// Output dumps: [{ key: 'key1', value: 'value1' }, { key: 'anotherKey', value: 'value3' }]

dumpToFile(obj, filename):

Writes the JSON object to a file.


const JsonManager = require('json-faster').JsonManager; // Replace with the path to your implementation

// Usage Example:
const manager = new JsonManager();

// init or clear data 
manager.init({}); // inits or clears with a blank object
manager.init(); // inits or clears with a blank object

// Adding data
manager.write('key1', 'value1');
manager.write('key2', 'value2');
manager.write('anotherKey', 'value3');
manager.write('keyWithValue1', 'value1');

// Searching for values
console.log(manager.searchValue('value1'));
// Output: [{ key: 'key1', value: 'value1' }, { key: 'keyWithValue1', value: 'value1' }]

console.log(manager.searchValue(['value1', 'value3']));
// Output: [{ key: 'key1', value: 'value1' }, { key: 'keyWithValue1', value: 'value1' }, { key: 'anotherKey', value: 'value3' }]

console.log(manager.searchValue('value', { like: true }));
// Output: [{ key: 'key1', value: 'value1' }, { key: 'key2', value: 'value2' }, { key: 'keyWithValue1', value: 'value1' }, { key: 'anotherKey', value: 'value3' }]

console.log(manager.searchValue('^value\\d$', { regex: true }));
// Output: [{ key: 'key1', value: 'value1' }, { key: 'key2', value: 'value2' }, { key: 'keyWithValue1', value: 'value1' }]


// Adding data
manager.write('key1', 'value1');
manager.write('key2', 'value2');
manager.write('anotherKey', 'value3');
manager.write('keyWithValue1', 'value1');

// Searching for key-value pairs
console.log(manager.searchKeyValue('key1'));
// Output: [{ key: 'key1', value: 'value1' }]

console.log(manager.searchKeyValue(['key1', 'value3']));
// Output: [{ key: 'key1', value: 'value1' }, { key: 'anotherKey', value: 'value3' }]

console.log(manager.searchKeyValue('value1', { like: true }));
// Output: [{ key: 'key1', value: 'value1' }, { key: 'keyWithValue1', value: 'value1' }]

console.log(manager.searchKeyValue('^key\\d$', { regex: true }));
// Output: [{ key: 'key1', value: 'value1' }, { key: 'key2', value: 'value2' }]

console.log(manager.searchKeyValue('value2', { regex: true }));
// Output: [{ key: 'key2', value: 'value2' }]

// Reading key
console.log(manager.read('key1', false)); // undefined
console.log(manager.read('key1', true)); // null

// Writing and checking
manager.write('key1', 'value1');
console.log(manager.hasKey('key1')); // true
console.log(manager.getKey('key1')); // 'value1'

// Dumping data
console.log(manager.dump()); // { key1: 'value1' }

// Dumping data based on criteria
console.log(manager.dumpKeys('key1', { like: true }, "search")); // { key1: 'value1' }
// Output: [{ key: 'key1', value: 'value1' }]

// Searching keys
manager.write('key2', 'value2');
manager.write('anotherKey', 'value3');

// Dumping data based on criteria
console.log(manager.dumpKeys(['key1', 'key3', 'anotherKey'], { like: true }, "search")); // { key1: 'value1' }
// Output dumps: [{ key: 'key1', value: 'value1' }, { key: 'anotherKey', value: 'value3' }]

// Search for specific keys in an array
console.log(manager.search(['key1', 'key3', 'anotherKey']));
// Output: [{ key: 'key1', value: 'value1' }, { key: 'anotherKey', value: 'value3' }]

// Search using partial match
console.log(manager.search('key', { like: true }));
// Output: [{ key: 'key1', value: 'value1' }, { key: 'key2', value: 'value2' }]

// Search using regex
console.log(manager.search('^key\\d$', { regex: true }));
// Output: [{ key: 'key1', value: 'value1' }, { key: 'key2', value: 'value2' }]

// Delete keys
manager.deleteKey('key2');

Flatten and Unflatten Json

// unflattenJson and unflatten work the same
const unflatten = require('json-faster').unflatten; // Replace with the path to your implementation

// flattenJsonWithEscaping and flatten work the same
const flatten = require('json-faster').flatten; // Replace with the path to your implementation

const writeToFile = require('json-faster').writeToFile;

const nestedData3 = {
    test: {
        "tester.makeup": {
            testing: "10",
            makeup: 10
        },
        madeup: 20
    },
    fakeup: 30
}

writeToFile(JSON.stringify(flatten(nestedData3)), "./demos/flattenjson.txt")
writeToFile(JSON.stringify(unflatten(flatten(nestedData3))), "./demos/unflattenjson.txt")