manus-json-processor
v1.0.1
Published
Advanced JSON manipulation and transformation library - Merge, flatten, transform, validate JSON
Maintainers
Readme
Manus JSON Processor
Advanced JSON manipulation and transformation library for Node.js. Merge, flatten, transform, and validate JSON with ease.
Features
- Deep merge - Recursively merge multiple JSON objects
- Flatten/Unflatten - Convert nested objects to flat structures and back
- Path access - Get/set values using dot notation paths
- Filter & Map - Filter and transform JSON objects
- Validation - Validate JSON against schemas
- Sorting - Sort JSON keys recursively
- Utilities - Clone, omit, pick, and more
- Zero dependencies - Lightweight and fast
Installation
npm install manus-json-processorQuick Start
const { JSONProcessor, merge, flatten } = require('manus-json-processor');
// Merge objects
const obj1 = { a: 1, b: 2 };
const obj2 = { c: 3 };
const merged = merge(obj1, obj2);
// { a: 1, b: 2, c: 3 }
// Flatten nested object
const nested = { user: { name: 'John', email: '[email protected]' } };
const flat = flatten(nested);
// { 'user.name': 'John', 'user.email': '[email protected]' }
// Get value by path
const value = JSONProcessor.getByPath(nested, 'user.name');
// 'John'Advanced Usage
const { JSONProcessor } = require('manus-json-processor');
// Deep merge with multiple objects
const config = JSONProcessor.deepMerge(
{ db: { host: 'localhost' } },
{ db: { port: 5432 } },
{ db: { user: 'admin' } }
);
// Filter JSON
const filtered = JSONProcessor.filter(obj, (key, value) =>
typeof value === 'string'
);
// Map JSON values
const mapped = JSONProcessor.map(obj, (value) =>
typeof value === 'string' ? value.toUpperCase() : value
);
// Sort keys recursively
const sorted = JSONProcessor.sortKeys(obj);
// Validate against schema
const schema = { name: 'string', age: 'number' };
const result = JSONProcessor.validate(obj, schema);API Reference
JSONProcessor Class
clone(obj)
Deep clone JSON object.
merge(...objects)
Merge multiple JSON objects (shallow).
deepMerge(target, ...sources)
Deep merge multiple JSON objects.
filter(obj, predicate)
Filter JSON by predicate function.
map(obj, mapper)
Map JSON values.
flatten(obj, prefix)
Flatten nested JSON object.
unflatten(obj)
Unflatten JSON object.
getByPath(obj, path)
Get value using dot notation path.
setByPath(obj, path, value)
Set value using dot notation path.
omit(obj, keys)
Remove specified keys from object.
pick(obj, keys)
Pick specified keys from object.
sortKeys(obj, recursive)
Sort JSON keys.
validate(obj, schema)
Validate JSON against schema.
getAllKeys(obj)
Get all keys recursively.
Convenience Functions
merge(...objects)- Merge objectsflatten(obj)- Flatten objectunflatten(obj)- Unflatten object
Examples
Configuration Management
const { JSONProcessor } = require('manus-json-processor');
const defaults = { api: { timeout: 5000, retries: 3 } };
const userConfig = { api: { timeout: 10000 } };
const config = JSONProcessor.deepMerge(defaults, userConfig);Data Transformation
const { flatten } = require('manus-json-processor');
const data = {
user: { name: 'John', email: '[email protected]' },
settings: { theme: 'dark', notifications: true }
};
const flat = flatten(data);
// Send to CSV or databaseAPI Response Processing
const { JSONProcessor } = require('manus-json-processor');
const response = { data: { users: [...], meta: { total: 100 } } };
const users = JSONProcessor.getByPath(response, 'data.users');
const total = JSONProcessor.getByPath(response, 'data.meta.total');Performance
- Handles deeply nested objects efficiently
- Optimized for large JSON structures
- Zero dependencies
- Fast transformation operations
License
MIT License
Support
For issues and questions: https://github.com/kokashinobi/manus-ai-tools/issues
Made with ❤️ by Manus AI
