colorisediff

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: Apache-2.0 Imports: 7 Imported by: 1

README

keploy logo

⚡️ API tests faster than unit tests, from user traffic ⚡️

🌟 The must-have tool for developers in the AI-Gen era 🌟


Keploy Twitter Help us reach 4k stars! Keploy CNCF Landscape

Slack LinkedIn YouTube Twitter

jsonDiff

jsonDiff is a Go package that allows you to compare JSON objects and return the differences as colorized strings.

Features

  • Compare two JSON objects and highlight the differences.
  • Supports comparing headers of expected and actual maps.
  • Provides colorized differences for easy visualization.

Installation

go get github.com/keploy/jsonDiff

Usage

Comparing JSON Objects

package main

import (
	"fmt"
	"github.com/keploy/jsonDiff"
)

func main() {
	json1 := []byte(`{"name": "Alice", "age": 30, "city": "New York"}`)
	json2 := []byte(`{"name": "Alice", "age": 31, "city": "Los Angeles"}`)

	diff, err := jsonDiff.ColorJSONDiff(json1, json2, nil)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	fmt.Println("Expected Response:")
	fmt.Println(diff.ExpectedResponse)
	fmt.Println("Actual Response:")
	fmt.Println(diff.ActualResponse)
}

Comparing Headers

package main

import (
	"fmt"
	"github.com/yourusername/jsonDiff"
)

func main() {
	expectedHeaders := map[string]string{
		"Content-Type": "application/json",
		"Authorization": "Bearer token123",
	}

	actualHeaders := map[string]string{
		"Content-Type": "application/json",
		"Authorization": "Bearer token456",
	}

	diff := jsonDiff.ColorHeaderDiff(expectedHeaders, actualHeaders)

	fmt.Println("Expected Headers:")
	fmt.Println(diff.ExpectedResponse)
	fmt.Println("Actual Headers:")
	fmt.Println(diff.ActualResponse)
}

👨🏻‍💻 Let's Build Together! 👩🏻‍💻

Whether you're a newbie coder or a wizard 🧙‍♀️, your perspective is golden. Take a peek at our:

📜 Contribution Guidelines

❤️ Code of Conduct

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Diff

type Diff struct {
	Expected string
	Actual   string
}

Diff holds the colorized differences between the expected and actual JSON responses. Expected: The colorized string representing the differences in the expected JSON response. Actual: The colorized string representing the differences in the actual JSON response.

func Compare

func Compare(expectedJSON, actualJSON string) Diff

Compare takes expected and actual JSON strings and returns the colorized differences. expectedJSON: The JSON string containing the expected values. actualJSON: The JSON string containing the actual values. Returns a Diff struct containing the colorized differences for the expected and actual JSON responses.

func CompareHeaders

func CompareHeaders(expectedHeaders, actualHeaders map[string]string) Diff

CompareHeaders compares the headers of the expected and actual maps and returns the differences as colorized strings. expect: The map containing the expected header values. actual: The map containing the actual header values. Returns a ColorizedResponse containing the colorized differences for the expected and actual headers.

func CompareJSON

func CompareJSON(expectedJSON []byte, actualJSON []byte, noise map[string][]string, disableColor bool) (Diff, error)

Jump to

Keyboard shortcuts

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