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 🙏

© 2024 – Pkg Stats / Ryan Hefner

json-file-comparator

v0.2.0

Published

json file comparator

Downloads

397

Readme

JSON File Comparator

codecov npm version

JSON File Comparator can compare two JSON files, compare result is based on JSONPath, then write result into another file. It will compare nodes at same level, based on node attribute, generate compare result.

Compared with other packages, it focus on big file comparasion, which will be out of memory if all loaded into memory.

Compare result has types:

  1. value_change: for the same node name, its value is changed .
  2. move: node is moved compared with same-name node at reference file.
  3. add: node is new added.
  4. removed: node is deleted.
  5. move_change: node is moved besides value changed.

There are three files involved:

Reference file: benchmark of the two compared file. All compared result above is based on this file.

Compare file: compared file with reference file, generate node difference as above.

Output file: file that write comparasion result into.

Usage

It accept four parameters as below:

Command

node json-file-comparator --reference=reference-file-path --compare=compare-file-path --output=output-file-path --size=10240

reference: reference file path

compare: compare file path

output: output file path

size: read file size. Change as memory requirement.

Funtion call

compare result is flattened because of performance issue while sync write. Basically it's like:

{
    "$.added-node": {
        "type": "add",
        "content": "newly added content, based on type various, it can be string/array/object/number"
    }, 
    "$.removed-node": {
        "type": "removed",
        "content": "removed content, based on type various, it can be string/array/object/number"
    },
    "$.moved-node": {
        "type": "move",
        "prevIndex": 0,
        "changedIndex": 2
    }, 
    "$.value-change-node": {
        "type": "value_change",
        "prevValue": "previous content in reference file, based on type various, it can be string/array/object/number",
        "changedValue": "updated content in compare file, based on type various, it can be string/array/object/number"
    },
    "$.move-change-node": {
        "type": "move_change",
        "prevIndex": 0,
        "changedIndex": 2,
         "prevValue": "previous content in reference file, based on type various, it can be string/array/object/number",
        "changedValue": "updated content in compare file, based on type various, it can be string/array/object/number"
    }
}

Roadmap

  • [X] Improve file read performance. Because it takes time when open file frequently, and read file based on file index, packages like highland might help.
  • [X] Huge JSON value compare process in stream way
  • [ ] Array comparasion. Array should not be compared based on key, value should be better choice. It can also help when it comes to key change scenario.
  • [X] Adjustable memory usage parameters.
  • [X] Online website. Which accept file upload and download comparasion result file, also JSON file comparasion result difference display.
  • [ ] In-memory JSON object comparasion.

Demo

Not availble for now but will be.