npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

diff-json-data

v1.0.4

Published

这是一个你可能需要的小工具~

Readme

diff-json-data

这是一个你可能需要的小工具~

它用于对比两个 json 之间的差异,然后最终输出一个 json 描述差异。这在你需要在两次接口返回的大量数据中找茬儿,寻找出中间的差异的时候还是挺好用的。

我最近做的一项工作就是,接口底层链路变更了,导致返回的数据与原本的数据存在着差异,我需要对比新旧接口返回数据的差异去做转换以及兼容。每次拿到两个非常庞大的对象的时候真的非常要命,看似没什么不同实际上,在对象深层的地方藏着非常细微的差别,导致了下游程序的崩溃。最终为了稳妥,我还是写了一个小工具来辅助我的工作,就是这个 diff-json-data。

GitHub 欢迎 star

如何安装

全局安装然后使用 cli

npm install -g diff-json-data
# or
yarn add -global diff-json-data

当然你也可以集成到你的项目里面去做一些奇怪的事情

npm install diff-json-data
# or
yarn add diff-json-data

如何使用

1. cli 的使用就非常的简单

diffjs -c path ./data1.json ./data2.json key new_interface old_interface

-c 表示你要进行两个 json 文件的对比

path 指令后面指定两个能寻找的到 json 文件的路径,使用空格隔开

key 指令后面指定两个 key 最终它会在 result.json 中体现,你也可以不指定,默认 key1 key2

你还可以使用 out 指令置顶结果 json 输出路径例如

diffjs -c path ./data1.json ./data2.json out ./interface_result.json

2. 集成到项目

这个项目就只导出了一个 diff function, 所以就直接拿到就用就行了

输入: (value1: object, value2: object, key1 = 'value1', key2 = 'value2', strict = false)

输出差异结构对象

E.g:

import diff from 'diff-json-data'

const result = diff({ hello: 'hhahah' }, { hello: 'hhahah', a: 1 })

console.log(result)

E.g

data1

{
  "IsPrint": false,
  "data": {
    "log_id": "5636805825537214258",
    "action_rule": {
      "pos_1": [],
      "pos_2": [],
      "pos_3": []
    }
  },
  "action_rule": {
    "pos_1": [],
    "pos_2": [],
    "pos_3": []
  },
  "pos_1": [],
  "pos_2": [],
  "pos_3": [],
  "log_id": "5636805825537214258",
  "errmsg": "ok",
  "errno": 0
}

data2

{
  "IsPrint": false,
  "data": {
    "log_id": "5636805825537214255",
    "action_rule": {
      "pos_1": [],
      "pos_2": [],
      "pos_3": []
    }
  },
  "action_rule": {
    "pos_1": [],
    "pos_2": [],
    "pos_3": []
  },
  "pos_1": [],
  "pos_2": [],
  "pos_3": [],
  "log_id": "5636805825537214256",
  "errmsg": "ok",
  "errno": 0
}
diffjs -c path ./data1.json ./data2.json key value1 value2

output ./result.json

{
  "data": {
    "log_id": {
      "diff": "inconsistent value!",
      "value1": "5636805825537214258",
      "value2": "5636805825537214255"
    }
  },
  "log_id": {
    "diff": "inconsistent value!",
    "value1": "5636805825537214258",
    "value2": "5636805825537214256"
  }
}

如果有用

1 分也是爱~