The jasonic
tool is a Node.js utility that allows you to synchronize specific fields between two JSON files. This tool was born out of a personal need, I had never worked with Nodejs so it is a bit experimental, it may have bad practices or things that can be improved. If someone wants to contribute, welcome.
npm install jasonic
const { syncJson } = require('jasonic');
The syncJson
function takes the following parameters:
sourcePath
(string): Path to the source JSON file.targetPath
(string): Path to the target JSON file.fields
(array): List of fields to be synchronized.options
(object, optional): Additional options for synchronization.
transform
(function): Transformation function applied to each field before synchronizing.log
(boolean): Enable or disable operation logs. Enabled by default.overwrite
(boolean): Allow or disallow overwriting existing fields in the target. Enabled by default.
const { syncJson } = require('jasonic');
const sourcePath = 'path/to/source.json';
const targetPath = 'path/to/target.json';
const fields = ['name', 'version', 'description'];
const options = {
transform: (key, value) => value.toUpperCase(),
log: true,
overwrite: true,
};
syncJson(sourcePath, targetPath, fields, options);
npm install -g jasonic
jasonic source.json target.json --fields name version description
{
"scripts": {
"sync-json": "jasonic source.json target.json --fields name version description"
}
}
npm run sync-json
npm test
This tool is licensed under the MIT License.