transform

package module
v0.0.0-...-bf227ec Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: MIT Imports: 15 Imported by: 0

README

Transformation Packages

Go Report Card

Useful JSON go packages

go get github.com/itsmurugappan/json
1. JSON Diff

Compares to JSON strings and gives the top level fields that has changed.

Example

import (
  "fmt"
  json "github.com/itsmurugappan/transform"
)

.....

a := `{"a": "1", "b": [{"a": "2"},{"a": "3"}], "c": {"a": "1"}}`
b := `{"c": {"a": "1", "b": "1"}, "a": "2", "b": [{"a": "2"},{"a": "3"}]}`

fmt.Println(json.Diff(a,b))


#OUT

[a,c]
2. JSON Parse and Validate

Parse and Validate a HTTP Request Body into the given json Struct

Example

Credits

The main packages I have used

  1. https://github.com/nsf/jsondiff
  2. https://github.com/go-playground/validator

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidInput = errors.New("input must be a struct pointer")

ErrInvalidInput indicates invalid input to parse the json string into

Functions

func Diff

func Diff(a, b string) []string

Diff compares 2 JSON strings and returns the changed/added/removed top level json objects

func JsonToSpec

func JsonToSpec(data []byte, spec interface{}) error

JsonToSpec transforms the byte array to the given struct

func ObjectDiff

func ObjectDiff(a, b, objectAPath, objectBPath string) []string

ObjectDiff compares specified object in 2 json strings returns the top level differences between the found objects

func ParseAndValidate

func ParseAndValidate(r *http.Request, spec interface{}) error

ParseAndValidate parses the HTTP request body into struct and Validate based on struct tags

func ParseReqBodyToSpec

func ParseReqBodyToSpec(r *http.Request, spec interface{}) error

ParseReqBodyToSpec parses HTTP request body into the given struct

func SpecFromMap

func SpecFromMap(data map[string]string, spec interface{}) error

SpecFromMap parses the given map into the spec

func SpecFromMapInterface

func SpecFromMapInterface(data map[string]interface{}, spec interface{}) error

SpecFromMap parses the given map into the spec

Types

This section is empty.

Jump to

Keyboard shortcuts

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