A JSON diff utility

JayDiff

Go Report Card GoDoc Build Status Coverage Status Maintainability

A JSON diff utility.

Install

Downloading the compiled binary

  • Download the latest version of the binary: releases
  • extract the archive and place the jaydiff binary in your $PATH

From source

  • Have go 1.11 or greater installed: golang.org
  • run go get -u github.com/yazgazan/jaydiff

Usage

Usage:
  jaydiff [OPTIONS] FILE_1 FILE_2

Application Options:
  -i, --ignore=               paths to ignore (glob)
      --indent=               indent string (default: "\t")
  -t, --show-types            show types
      --json                  json-style output
      --ignore-excess         ignore excess keys and array elements
      --ignore-values         ignore scalar's values (only type is compared)
  -r, --report                output report format
      --slice-myers           use myers algorithm for slices
      --stream                treat FILE_1 and FILE_2 as JSON streams
      --stream-lines          read JSON stream line by line (expecting 1 JSON value per line)
      --stream-ignore-excess  ignore excess values in JSON stream
      --stream-validate       compare FILE_2 JSON stream against FILE_1 single value
  -v, --version               print release version

Help Options:
  -h, --help                  Show this help message

Examples

Getting a full diff of two json files:

$ jaydiff --show-types old.json new.json

 map[string]interface {} map[
     a: float64 42
     b: []interface {} [
         float64 1
-        float64 3
+        float64 5
+        float64 4
     ]
     c: map[string]interface {} map[
-        a: string toto
+        a: string titi
-        b: float64 23
+        b: string 23
     ]
-    e: []interface {} []
-    f: float64 42
     g: []interface {} [1 2 3]
+    h: float64 42
 ]

Ignoring fields:

$ jaydiff --show-types \
    --ignore='.b\[\]' --ignore='.d' --ignore='.c.[ac]' \
      old.json new.json

 map[string]interface {} map[
     a: float64 42
     b: []interface {} [1 3]
     c: map[string]interface {} map[
-        b: float64 23
+        b: string 23
     ]
-    e: []interface {} []
-    f: float64 42
     g: []interface {} [1 2 3]
+    h: float64 42
 ]

Report format:

$ jaydiff --report --show-types old.json new.json

- .b[1]: float64 3
+ .b[1]: float64 5
+ .b[2]: float64 4
- .c.a: string toto
+ .c.a: string titi
- .c.b: float64 23
+ .c.b: string 23
- .e: []interface {} []
- .f: float64 42
+ .h: float64 42

JSON-like format:

$ jaydiff --json old.json new.json

 {
     "a": 42,
     "b": [
         1,
-        3,
+        5,
+        4
     ],
     "c": {
-        "a": "toto",
+        "a": "titi",
-        "b": 23,
+        "b": "23"
     },
-    "e": [],
-    "f": 42,
     "g": [1,2,3],
+    "h": 42
 }

Ignore Excess values (useful when checking for backward compatibility):

$ jaydiff --report --show-types --ignore-excess old.json new.json

- .b[1]: float64 3
+ .b[1]: float64 5
- .c.a: string toto
+ .c.a: string titi
- .c.b: float64 23
+ .c.b: string 23
- .e: []interface {} []
- .f: float64 42

Ignore values (type must still match):

$ jaydiff --report --show-types --ignore-excess --ignore-values old.json new.json

- .c.b: float64 23
+ .c.b: string 23
- .e: []interface {} []
- .f: float64 42

JSON streams:

$ jaydiff --stream --json old.json new.json

 [
      {"foo":"bar"},
     [
         2,
         3,
         4,
         {
+            "v": "some"
         }
     ],
+    {"some":"thing"}
 ]

Validating JSON stream types:

$ jaydiff --ignore-excess --ignore-values --stream-validate --report --show-types base.json stream.json

- [1].bar: float64 4.2
+ [1].bar: string !

Ideas

  • JayPatch

Sponsored by Datumprikker.nl

Owner
Similar Resources

A Go package for handling common HTTP JSON responses.

go-respond A Go package for handling common HTTP JSON responses. Installation go get github.com/nicklaw5/go-respond Usage The goal of go-respond is to

Sep 26, 2022

JSON query in Golang

gojq JSON query in Golang. Install go get -u github.com/elgs/gojq This library serves three purposes: makes parsing JSON configuration file much easie

Dec 28, 2022

Automatically generate Go (golang) struct definitions from example JSON

gojson gojson generates go struct definitions from json or yaml documents. Example $ curl -s https://api.github.com/repos/chimeracoder/gojson | gojson

Jan 1, 2023

Fast and flexible JSON encoder for Go

Fast and flexible JSON encoder for Go

Jettison Jettison is a fast and flexible JSON encoder for the Go programming language, inspired by bet365/jingo, with a richer features set, aiming at

Dec 21, 2022

Create go type representation from json

json2go Package json2go provides utilities for creating go type representation from json inputs. Json2go can be used in various ways: CLI tool Web pag

Dec 26, 2022

Console JSON formatter with query feature

Console JSON formatter with query feature

Console JSON formatter with query feature. Install: $ go get github.com/miolini/jsonf Usage: Usage of jsonf: -c=true: colorize output -d=false: de

Dec 4, 2022

Fluent API to make it easier to create Json objects.

Jsongo Fluent API to make it easier to create Json objects. Install go get github.com/ricardolonga/jsongo Usage To create this: { "name":"Ricar

Nov 7, 2022

Arbitrary transformations of JSON in Golang

kazaam Description Kazaam was created with the goal of supporting easy and fast transformations of JSON data with Golang. This functionality provides

Dec 18, 2022

Parsing JSON is a hassle in golang

GoJSON Parsing JSON is a hassle in golang. This package will allow you to parse and search elements in a json without structs. Install gojson go get g

Nov 12, 2021
Comments
  • wrongly throwing cyclical error due to typo

    wrongly throwing cyclical error due to typo

    The bug comes from diff.go, line 193:

    if canAddr(rhs) && !isEmptyMapOrSlice(lhs) {

    should be

    if canAddr(rhs) && !isEmptyMapOrSlice(rhs) {

  • Adding support for JSON streams

    Adding support for JSON streams

    Integrating @e11it's feature request (see #22)

    • JSON streams are supported in the .../jaydiff/diff library
    • Line-by-line reading of JSON streams is possible via the --stream-lines option
    • Ignoring excess values in JSON stream is separated from the map/arrays flag (--stream-ignore-excess)
    • Using LHS file as single-value validator is supported via --stream-validate
  • Cyclical error wrong check

    Cyclical error wrong check

    In visited.add, lhs was checked for an empty map/slice when handling the rhs side of the cyclical detection.

    This was causing Diff to return an error when an empty slice or map was repeated on the right-hand side:

    lhs := map[string]interface{}{
    	"0": "baz",
    	"1": 2,
    }
    rhs := map[string]interface{}{
    	"0": []string{},
    }
    rhs["1"] = rhs["0"]
    
    _, err := Diff(lhs, rhs) // here err should be nil, as empty maps and slices can never result in a circular reference.
    

    Fixes #13

  • Improving circular reference detection

    Improving circular reference detection

    Our circular reference detection currently returns false positives when addressable values are repeated in a non-problematic pattern:

    lhs := map[string]interface{}{
    	"0": "baz",
    	"1": 2,
    }
    rhs := map[string]interface{}{
    	"0": new(int),
    }
    rhs["1"] = rhs["0"]
    
    _, err := Diff(lhs, rhs) // here err should be nil, as empty maps and slices can never result in a circular reference.
    

    https://github.com/yazgazan/jaydiff/blob/f993f5d2dd4272f4a8afab68117b3d4c443ca237/diff/diff_test.go#L662-L665

Related tags
/ˈdʏf/ - diff tool for YAML files, and sometimes JSON
/ˈdʏf/ - diff tool for YAML files, and sometimes JSON

dyff is inspired by the way the old BOSH v1 deployment output reported changes from one version to another by only showing the parts of a YAML file that change.

Dec 29, 2022
Small utility to create JSON objects
Small utility to create JSON objects

gjo Small utility to create JSON objects. This was inspired by jpmens/jo. Support OS Mac Linux Windows Requirements Go 1.1.14~ Git Installtion Build $

Dec 8, 2022
Get JSON values quickly - JSON parser for Go
Get JSON values quickly - JSON parser for Go

get json values quickly GJSON is a Go package that provides a fast and simple way to get values from a json document. It has features such as one line

Dec 28, 2022
Fast JSON encoder/decoder compatible with encoding/json for Go
Fast JSON encoder/decoder compatible with encoding/json for Go

Fast JSON encoder/decoder compatible with encoding/json for Go

Jan 6, 2023
Package json implements encoding and decoding of JSON as defined in RFC 7159

Package json implements encoding and decoding of JSON as defined in RFC 7159. The mapping between JSON and Go values is described in the documentation for the Marshal and Unmarshal functions

Jun 26, 2022
Json-go - CLI to convert JSON to go and vice versa
Json-go - CLI to convert JSON to go and vice versa

Json To Go Struct CLI Install Go version 1.17 go install github.com/samit22/js

Jul 29, 2022
JSON Spanner - A Go package that provides a fast and simple way to filter or transform a json document

JSON SPANNER JSON Spanner is a Go package that provides a fast and simple way to

Sep 14, 2022
simple utility to compare the node's latest block with the source of truth

Near Deer A simple utility to compare the node's latest block with the source of truth (checks against https://rpc..near.org/status) Example usage: al

Dec 13, 2021
Abstract JSON for golang with JSONPath support

Abstract JSON Abstract JSON is a small golang package provides a parser for JSON with support of JSONPath, in case when you are not sure in its struct

Jan 5, 2023
Fast JSON parser and validator for Go. No custom structs, no code generation, no reflection

fastjson - fast JSON parser and validator for Go Features Fast. As usual, up to 15x faster than the standard encoding/json. See benchmarks. Parses arb

Jan 5, 2023