Skip to content

Small zero-dependency library for editing JSON-object keys and values without reordering.

License

Notifications You must be signed in to change notification settings

tagimu/edit-json

Repository files navigation

Pre alfa

🔨 Implementation in progress...

Deep pre-alfa.

Edit JSON

Small zero-dependency library for editing JSON keys and values without reordering.

Installation

How to use

API

json = new JsonUpdater({...} | jsonString);

// Add new value
json.add('key', 'value');
// Remove from json
json.remove('key');
// Change key name withou reordering!
json.updateKey('old key', 'new key');
// You can use path to key as parameter
// Next command returns this json:
// {
//     "scripts": {
//         "build:app": "something"
//     }
// }
json.updateKey('scripts.build', 'build:app');
// Change all keys with name "key" in array
json.updateKey('engines[].key', 'newKey');
// Change only first key with name "key" in array
json.updateKey('engines[0].key', 'newKey');
// Update value by path
json.updateValue('scripts.build:app', 'node build.js');
json.updateValue('scripts.build:app', { "name": "John" });
// Build object.
// After making object you still can edit json with JsonUpdater
// But you need to call .toObject() again to commit changes
json.toObject() // returns Object
// Build JSON string
json.toJson() // returns string

License

About

Small zero-dependency library for editing JSON-object keys and values without reordering.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published