Skip to main content

No project description provided

Project description

Object Diff

Object diff (odiff) is a little tool/library for diffing objects - it's a little specific in a couple of places to a thing I'm doing at work but it might be useful elsewhere.

Essentially, you feed it two files, JSON or YAML, to compare and discrepancies are listed in the console.

Usage

usage: odiff [-h] [--log-level LOG_LEVEL] [--output-type OUTPUT_TYPE]
             [--list-cfg LIST_CFG]
             [files ...]

positional arguments:
  files                 two files to diff

options:
  -h, --help            show this help message and exit
  --log-level LOG_LEVEL
                        log level name
  --output-type OUTPUT_TYPE, --output OUTPUT_TYPE, -o OUTPUT_TYPE
                        report output flavour
  --config CONFIG, -c CONFIG
                        yaml config file

Example Output

odiff -c aux/eg-cfg.yaml aux/eg1.json aux/eg2.json
[WARN:odiff] Discrepancy found for path '.alpha' but was excluded
╭──────────────┬────────────┬────────────────┬───────────────────────╮
│ Variant      │ Path       │ Lvalue         │ Rvalue                │
├──────────────┼────────────┼────────────────┼───────────────────────┤
│ modification │ .beta      │ world          │ , world               │
├──────────────┼────────────┼────────────────┼───────────────────────┤
│ subtraction  │ .gamma[]   │ None           │ [                     │
│              │            │                │   "isn't",            │
│              │            │                │   "not-in-eg1"        │
│              │            │                │ ]                     │
├──────────────┼────────────┼────────────────┼───────────────────────┤
│ addition     │ .gamma[]   │ [              │ None                  │
│              │            │   "is",        │                       │
│              │            │   "not-in-eg2" │                       │
│              │            │ ]              │                       │
├──────────────┼────────────┼────────────────┼───────────────────────┤
│ subtraction  │ .delta[    │ None           │ {                     │
│              │   Ct2fhriU │                │   "_id": "Ct2fhriU",  │
│              │ ]          │                │   "key1": "i'm added" │
│              │            │                │ }                     │
├──────────────┼────────────┼────────────────┼───────────────────────┤
│ modification │ .delta[    │ value0         │ i've been modified    │
│              │   vCjpIL2A │                │                       │
│              │ ].key0     │                │                       │
╰──────────────┴────────────┴────────────────┴───────────────────────╯

Instead of using a configuration file (see Configuration) you can also provide the same configuration directly in the command:

odiff aux/eg1.json aux/eg2.json --li '.delta: _id' --exc '.alpha'

Configuration

List Index Configuration

You may have spotted in the Example Output that we pass the -c option (--list-config) and that the output made use of this key in the children of .delta to "align" the list elements together - this allows us to diff matching objects despite them not necessarily being the correct order.

The format of this is a simple string-string, key-value pairing in YAML, e.g.:

.delta: _id

You can see it takes a JQ-ish form for the object pathing. So, if your input is a list of object, you should provide an index for the . key.

Exclusions

Another thing you may have spotted in the output is the log line at the top about the excluded discrepancy on .alpha.

This is what the .exclusions list is for, anything you wish to ignore in either the left or right file can be listed here.

Contributing

This repo uses Pre-commit for some sanity checks, so:

pre-commit install

There are literally zero tests aside the examples...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

odiff-0.1.4.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

odiff-0.1.4-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file odiff-0.1.4.tar.gz.

File metadata

  • Download URL: odiff-0.1.4.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 Linux/6.5.0-1022-azure

File hashes

Hashes for odiff-0.1.4.tar.gz
Algorithm Hash digest
SHA256 59ed51eb8559e520f2a7858a2cd659e041b67741fdceb8ca0125996848cbcb92
MD5 948389e6442dec8957b768e28c9771de
BLAKE2b-256 f168e5ac212928ae7c0dc5ea3cf02ce012e85a2d844ec3658971a2fcc7eb2efa

See more details on using hashes here.

File details

Details for the file odiff-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: odiff-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 Linux/6.5.0-1022-azure

File hashes

Hashes for odiff-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8d3027efd81d843cc138eeb921b6ec8d5e536107086fb2958f73399e33d3fafc
MD5 8363df4f3f2620ba90001a54bf4deeac
BLAKE2b-256 a571b4a0b04ab5b63266bdab7e408d605f3cc838bafcb48984a5c27ab4d84c00

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page