MCPcopy Create free account
hub / github.com/conforma/cli / compareJSON

Function compareJSON

acceptance/cli/cli.go:873–895  ·  view source on GitHub ↗

gojsondiff handles arrays and maps different gojsondiff.Compare unmarshals to map[string]interface{}

(left []byte, right []byte, isArray bool)

Source from the content-addressed store, hash-verified

871// gojsondiff handles arrays and maps different
872// gojsondiff.Compare unmarshals to map[string]interface{}
873func compareJSON(left []byte, right []byte, isArray bool) (gojsondiff.Diff, error) {
874 differ := gojsondiff.New()
875 var err error
876 var diff gojsondiff.Diff
877 if isArray {
878 var leftObj, rightObj []interface{}
879 err = json.Unmarshal(left, &leftObj)
880 if err != nil {
881 return nil, err
882 }
883 err = json.Unmarshal(right, &rightObj)
884 if err != nil {
885 return nil, err
886 }
887 diff = differ.CompareArrays(leftObj, rightObj)
888 } else {
889 diff, err = differ.Compare(left, right)
890 if err != nil {
891 return nil, err
892 }
893 }
894 return diff, nil
895}
896
897// theEnvironmentVarilableIsSet sets the given environment variable to be used
898// when launching a command.

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected