Transform JSON like a pro. Query, reshape, flatten, diff, and convert JSON data. jq alternative for Node.
npm install @lxgicstudios/jsonmorphTransform JSON like a pro. Query, reshape, flatten, diff, and convert JSON data. A jq alternative for Node.
``bash`
npm install -g @lxgicstudios/jsonmorph
Or use directly:
`bash`
npx @lxgicstudios/jsonmorph query data.json ".users[*].name"
`bashGet nested value
jsonmorph query data.json ".config.database.host"
$3
`bash
Flatten nested object to dot notation
jsonmorph flatten nested.json
{ "user.name": "John", "user.address.city": "NYC" }
Unflatten back to nested
jsonmorph unflatten flat.json
`$3
`bash
jsonmorph diff old.json new.json
`Output:
`
+ Added:
users[2].name- Removed:
config.debug
~ Changed:
version: "1.0.0" โ "2.0.0"
`$3
`bash
jsonmorph merge base.json overrides.json -o merged.json
`$3
`bash
Keep only specific keys
jsonmorph pick user.json name emailRemove specific keys
jsonmorph omit user.json password ssn
`$3
`bash
Rename keys
jsonmorph transform data.json "id:_id,name:title"
`$3
`bash
jsonmorph validate data.json schema.json
`$3
`bash
jsonmorph minify data.json -o data.min.json
jsonmorph prettify data.min.json
`Path Syntax
| Syntax | Description |
|--------|-------------|
|
.key | Access object property |
| [0] | Access array index |
| [*] | All array elements |
| ..key | Deep search for key |Programmatic Usage
`javascript
const { query, flatten, diff, merge } = require('@lxgicstudios/jsonmorph');// Query
const names = query(data, '.users[*].name');
// Flatten
const flat = flatten({ user: { name: 'John' } });
// { 'user.name': 'John' }
// Diff
const changes = diff(oldData, newData);
// Merge
const merged = merge(defaults, userConfig);
``- Zero dependencies - Pure JavaScript
- Intuitive syntax - Similar to jq but simpler
- Powerful diffing - See exactly what changed
- Schema validation - Catch errors early
---
Built by LXGIC Studios