simple_json_compare

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2021 License: MIT Imports: 8 Imported by: 0

README

simple_json_compare

A very rudimentary JSON compare package

Ignore path that end with "->*" will ignore last element Example:

  • Ignore Spec ==> "root->target->end_time->*"
  • Ignored ==> "root->target->end_time"
  • Ignored ==> "root->target->end_time->08:13:13"
  • Not Ignored ==> "root->target->end_time->date->08-13-1988"

Ignore path that ends with "->*R[regex]" will ignore last element if it matches the supplied regular expression

  • Ignore Spec ==> "root->address->->connectivity->->ips->*R[->\d+->\d+\.\d+\.\d+\.\d+;\d+]"
  • Ignored ==> "root->address->->connectivity->->ips->0->169.254.169.254;8"
  • Not Ignored ==> "root->address->->connectivity->->ips->0->169.254.169.254;8a"

Sample code

package main

import (
	"fmt"
	"github.com/CalypsoSys/simple_json_compare"
)

func main() {
	ignorePaths := []string{"root->target->end_time->*", "root->data->*->pct_used->*"}
	diff, differences, err := simple_json_compare.CompareJSONFiles("test1.json", "test2.json", ignorePaths)
	if err != nil {
		fmt.Printf("Errors: %v+\n", err)
	} else if diff == false {
		fmt.Println("JSON is idential")
	} else {
		fmt.Println("JSON Differences:")
		for _, difference := range differences {
			fmt.Printf("\t%s\n", difference)
		}
	}
}

Documentation

Overview

Package simple_json_compare implements a very simplicstic json compare function

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareJSONBytes

func CompareJSONBytes(leftBytes []byte, rightBytes []byte, ignorePaths []string) (bool, []string, error)

CompareJSONBytes - Compare JSON from 2 byte arrays

func CompareJSONFiles

func CompareJSONFiles(leftPath string, rightPath string, ignorePaths []string) (bool, []string, error)

CompareJSONFiles - Compare JSON from 2 file sources

func CompareJSONStrings

func CompareJSONStrings(leftString string, rightString string, ignorePaths []string) (bool, []string, error)

CompareJSONStrings - Compare JSON from 2 strings

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL