README ¶
Transformation Packages
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
Credits
The main packages I have used
Documentation ¶
Index ¶
- Variables
- func Diff(a, b string) []string
- func JsonToSpec(data []byte, spec interface{}) error
- func ObjectDiff(a, b, objectAPath, objectBPath string) []string
- func ParseAndValidate(r *http.Request, spec interface{}) error
- func ParseReqBodyToSpec(r *http.Request, spec interface{}) error
- func SpecFromMap(data map[string]interface{}, spec interface{}) error
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidInput = errors.New("input must be a struct pointer")
ErrInvalidInput indicates invalid input to parse the json string into
Functions ¶
func Diff ¶
Diff compares 2 JSON strings and returns the changed/added/removed top level json objects
func JsonToSpec ¶
JsonToSpec transforms the byte array to the given struct
func ObjectDiff ¶
ObjectDiff compares specified object in 2 json strings returns the top level differences between the found objects
func ParseAndValidate ¶
ParseAndValidate parses the HTTP request body into struct and Validate based on struct tags
func ParseReqBodyToSpec ¶
ParseReqBodyToSpec parses HTTP request body into the given struct
func SpecFromMap ¶
SpecFromMap parses the given map into the spec
Types ¶
This section is empty.