Gathering detailed insights and metrics for @audc/json-diff-ts
Gathering detailed insights and metrics for @audc/json-diff-ts
Gathering detailed insights and metrics for @audc/json-diff-ts
Gathering detailed insights and metrics for @audc/json-diff-ts
npm install @audc/json-diff-ts
Typescript
Module System
Node Version
NPM Version
71.9
Supply Chain
99.4
Quality
75.2
Maintenance
100
Vulnerability
99.6
License
TypeScript (98.49%)
JavaScript (1.51%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
141 Stars
439 Commits
27 Forks
2 Watchers
22 Branches
13 Contributors
Updated on Jul 18, 2025
Latest Version
1.2.4
Package Id
@audc/json-diff-ts@1.2.4
Unpacked Size
34.14 kB
Size
8.42 kB
File Count
9
NPM Version
8.5.0
Node Version
16.14.2
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
TypeScript diff tool with support for array keys instead of just indexes and compatible with JSONPath.
If a key is specified for an embedded array, the diff will be generated based on the objects have same keys.
1var changesets = require('json-diff-ts'); 2var newObj, oldObj; 3 4oldObj = { 5 name: 'joe', 6 age: 55, 7 coins: [2, 5], 8 children: [ 9 { name: 'kid1', age: 1 }, 10 { name: 'kid2', age: 2 } 11 ] 12}; 13 14newObj = { 15 name: 'smith', 16 coins: [2, 5, 1], 17 children: [ 18 { name: 'kid3', age: 3 }, 19 { name: 'kid1', age: 0 }, 20 { name: 'kid2', age: 2 } 21 ] 22}; 23 24// Assume children is an array of child object and the child object has 'name' as its primary key 25// keys can also be hierarchical e.g. {children: 'name', 'children.grandChildren', 'age'} 26// or use functions that return the key of an object e.g. {children: function(obj) { return obj.key; }} 27diffs = changesets.diff(oldObj, newObj, { children: 'name' }); 28 29expect(diffs).to.eql([ 30 { 31 type: 'update', 32 key: 'name', 33 value: 'smith', 34 oldValue: 'joe' 35 }, 36 { 37 type: 'update', 38 key: 'coins', 39 embededKey: '$index', 40 changes: [{ type: 'add', key: '2', value: 1 }] 41 }, 42 { 43 type: 'update', 44 key: 'children', 45 embededKey: 'name', 46 changes: [ 47 { 48 type: 'update', 49 key: 'kid1', 50 changes: [{ type: 'update', key: 'age', value: 0, oldValue: 1 }] 51 }, 52 { 53 type: 'add', 54 key: 'kid3', 55 value: { name: 'kid3', age: 3 } 56 } 57 ] 58 }, 59 { 60 type: 'remove', 61 key: 'age', 62 value: 55 63 } 64]);
Converts the changeset into a flat atomic change list compatible with JSONPath.
1const flatChanges = flattenChangeset(diffs); 2// convert changes back to changeset format 3const changeset = unflattenChanges(flatChanges.slice(1, 5)); 4// or use a JSONPath library to apply the patches 5// ...
The flatChange format will look like this:
1[ 2 { type: 'UPDATE', key: 'name', value: 'smith', oldValue: 'joe', path: '$.name', valueType: 'String' }, 3 { type: 'REMOVE', key: 'mixed', value: 10, path: '$.mixed', valueType: 'Number' }, 4 { type: 'UPDATE', key: 'inner', value: 2, oldValue: 1, path: '$.nested.inner', valueType: 'Number' }, 5 { 6 type: 'UPDATE', 7 key: 'date', 8 value: '2014-10-12T09:13:00.000Z', 9 oldValue: '2014-10-13T09:13:00.000Z', 10 path: '$.date', 11 valueType: 'Date' 12 }, 13 { type: 'ADD', key: '2', value: 1, path: '$.coins[2]', valueType: 'Number' }, 14 { type: 'REMOVE', key: '0', value: 'car', path: '$.toys[0]', valueType: 'String' }, 15 { type: 'REMOVE', key: '1', value: 'doll', path: '$.toys[1]', valueType: 'String' }, 16 { type: 'REMOVE', key: '0', path: '$.pets[0]', valueType: 'undefined' }, 17 { type: 'REMOVE', key: '1', value: null, path: '$.pets[1]', valueType: null }, 18 { type: 'UPDATE', key: 'age', value: 0, oldValue: 1, path: "$.children[?(@.name='kid1')].age", valueType: 'Number' }, 19 { 20 type: 'UPDATE', 21 key: 'value', 22 value: 'heihei', 23 oldValue: 'haha', 24 path: "$.children[?(@.name='kid1')].subset[?(@.id='1')].value", 25 valueType: 'String' 26 }, 27 { 28 type: 'REMOVE', 29 key: '2', 30 value: { id: 2, value: 'hehe' }, 31 path: "$.children[?(@.name='kid1')].subset[?(@.id='2')]", 32 valueType: 'Object' 33 }, 34 { type: 'ADD', key: 'kid3', value: { name: 'kid3', age: 3 }, path: '$.children', valueType: 'Object' } 35];
1var changesets = require('json-diff-ts'); 2var oldObj = { 3 name: 'joe', 4 age: 55, 5 coins: [2, 5], 6 children: [ 7 { name: 'kid1', age: 1 }, 8 { name: 'kid2', age: 2 } 9 ] 10}; 11 12// Assume children is an array of child object and the child object has 'name' as its primary key 13diffs = [ 14 { 15 type: 'update', 16 key: 'name', 17 value: 'smith', 18 oldValue: 'joe' 19 }, 20 { 21 type: 'update', 22 key: 'coins', 23 embededKey: '$index', 24 changes: [{ type: 'add', key: '2', value: 1 }] 25 }, 26 { 27 type: 'update', 28 key: 'children', 29 embededKey: 'name', // The key property name of the elements in an array 30 changes: [ 31 { 32 type: 'update', 33 key: 'kid1', 34 changes: [{ type: 'update', key: 'age', value: 0, oldValue: 1 }] 35 }, 36 { 37 type: 'add', 38 key: 'kid3', 39 value: { name: 'kid3', age: 3 } 40 } 41 ] 42 }, 43 { 44 type: 'remove', 45 key: 'age', 46 value: 55 47 } 48]; 49 50changesets.applyChanges(oldObj, diffs); 51expect(oldObj).to.eql({ 52 name: 'smith', 53 coins: [2, 5, 1], 54 children: [ 55 { name: 'kid3', age: 3 }, 56 { name: 'kid1', age: 0 }, 57 { name: 'kid2', age: 2 } 58 ] 59});
1 2 var changesets = require('json-diff-ts'); 3 4 var newObj = { 5 name: 'smith', 6 coins: [2, 5, 1], 7 children: [ 8 {name: 'kid3', age: 3}, 9 {name: 'kid1', age: 0}, 10 {name: 'kid2', age: 2} 11 ]}; 12 13 // Assume children is an array of child object and the child object has 'name' as its primary key 14 diffs = [ 15 { 16 type: 'update', key: 'name', value: 'smith', oldValue: 'joe' 17 }, 18 { 19 type: 'update', key: 'coins', embededKey: '$index', changes: [ 20 {type: 'add', key: '2', value: 1 } 21 ] 22 }, 23 { 24 type: 'update', 25 key: 'children', 26 embededKey: 'name', // The key property name of the elements in an array 27 changes: [ 28 { 29 type: 'update', key: 'kid1', changes: [ 30 {type: 'update', key: 'age', value: 0, oldValue: 1 } 31 ] 32 }, 33 { 34 type: 'add', key: 'kid3', value: {name: 'kid3', age: 3 } 35 } 36 ] 37 }, 38 { 39 type: 'remove', key: 'age', value: 55 40 } 41 ] 42 43 changesets.revertChanges(newObj, diffs) 44 expect(newObj).to.eql { 45 name: 'joe', 46 age: 55, 47 coins: [2, 5], 48 children: [ 49 {name: 'kid1', age: 1}, 50 {name: 'kid2', age: 2} 51 ]}; 52
npm install json-diff-ts
npm run test
Blog: https://blog.leitwolf.io
Twitter: @cglessner
This project was based on https://www.npmjs.com/package/diff-json (viruschidai@gmail.com)
The MIT License (MIT)
Copyright (c) 2019 Christian Glessner
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The project is based on diff-json (https://www.npmjs.com/package/diff-json). Copyright 2013 viruschidai@gmail.com. for additional details.
Original License
The MIT License (MIT)
Copyright (c) 2013 viruschidai@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
30 commit(s) and 7 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
SAST tool is run on all commits
Details
Reason
2 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
Found 0/5 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More