Categorygithub.com/goto/gojsondiff
modulepackage
0.0.0-20230828102327-0bcf3724fe2e
Repository: https://github.com/goto/gojsondiff.git
Documentation: pkg.go.dev

# README

Go JSON Diff (and Patch)

Wercker GoDoc MIT License

How to use

Installation

go get github.com/yudai/gojsondiff

Comparing two JSON strings

See jd/main.go for how to use this library.

CLI tool

This repository contains a package that you can use as a CLI tool.

Installation

go get github.com/yudai/gojsondiff/jd

Usage

Diff

Just give two json files to the jd command:

jd one.json another.json

Outputs would be something like:

 {
   "arr": [
     0: "arr0",
     1: 21,
     2: {
       "num": 1,
-      "str": "pek3f"
+      "str": "changed"
     },
     3: [
       0: 0,
-      1: "1"
+      1: "changed"
     ]
   ],
   "bool": true,
   "num_float": 39.39,
   "num_int": 13,
   "obj": {
     "arr": [
       0: 17,
       1: "str",
       2: {
-        "str": "eafeb"
+        "str": "changed"
       }
     ],
+    "new": "added",
-    "num": 19,
     "obj": {
-      "num": 14,
+      "num": 9999
-      "str": "efj3"
+      "str": "changed"
     },
     "str": "bcded"
   },
   "str": "abcde"
 }

When you prefer the delta format of jsondiffpatch, add the -f delta option.

jd -f delta one.json another.json

This command shows:

{
  "arr": {
    "2": {
      "str": [
        "pek3f",
        "changed"
      ]
    },
    "3": {
      "1": [
        "1",
        "changed"
      ],
      "_t": "a"
    },
    "_t": "a"
  },
  "obj": {
    "arr": {
      "2": {
        "str": [
          "eafeb",
          "changed"
        ]
      },
      "_t": "a"
    },
    "new": [
      "added"
    ],
    "num": [
      19,
      0,
      0
    ],
    "obj": {
      "num": [
        14,
        9999
      ],
      "str": [
        "efj3",
        "changed"
      ]
    }
  }
}

Patch

Give a diff file in the delta format and the JSON file to the jp command.

jp diff.delta one.json

License

MIT License (see LICENSE for detail)

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

New returns new Differ with default configuration.
NewAdded returns a new Added.
NewArray returns an Array.
NewDeleted returns a Deleted.
NewModified returns a Modified.
No description provided by the author
NewObject returns an Object.
NewTextDiff returns.
No description provided by the author

# Structs

An Added represents a new added field of an object or an array.
An Array is a Delta that represents an array of JSON.
A Delted represents deleted field or index of an Object or an Array.
A Differ conmapres JSON objects and apply patches.
A Modified represents a field whose value is changed.
A Moved represents field that is moved, which means the index or name is changed.
An Object is a Delta that represents an object of JSON.
A TextDiff represents a Modified with TextDiff between the old and the new values.
No description provided by the author

# Interfaces

A Delta represents an atomic difference between two JSON objects.
A Diff holds deltas generated by a Differ.
A Position represents the position of a Delta in an object or an array.
A PreDelta is a Delta that has a position of the right side JSON object.
A PreDelta is a Delta that has a position of the left side JSON object.

# Type aliases

A Index is a Position with an int value, which means the Delta is in an Array.
A Name is a Postition with a string, which means the delta is in an object.