metadataEqual compares two JSON byte slices for semantic equality by parsing them into maps and re-marshaling them. This handles cases where the JSON is equivalent but formatted differently (whitespace, field order, etc).
(a, b []byte)
| 1090 | // them into maps and re-marshaling them. This handles cases where the JSON is |
| 1091 | // equivalent but formatted differently (whitespace, field order, etc). |
| 1092 | func metadataEqual(a, b []byte) bool { |
| 1093 | var unmarshaledA, unmarshaledB map[string]any |
| 1094 | if err := json.Unmarshal(a, &unmarshaledA); err != nil { |
| 1095 | return false |
| 1096 | } |
| 1097 | if err := json.Unmarshal(b, &unmarshaledB); err != nil { |
| 1098 | return false |
| 1099 | } |
| 1100 | marshaledA, err := json.Marshal(unmarshaledA) |
| 1101 | if err != nil { |
| 1102 | return false |
| 1103 | } |
| 1104 | marshaledB, err := json.Marshal(unmarshaledB) |
| 1105 | if err != nil { |
| 1106 | return false |
| 1107 | } |
| 1108 | return bytes.Equal(marshaledA, marshaledB) |
| 1109 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…