Deviopath › Go

Merge JSON Objects

Hard · Encoding

Unmarshal two JSON objects and merge them. Keys in override win. Values stay JSON-decoded (numbers as float64). Return the merged object as JSON with keys sorted (json.Marshal on a map does not sort — build via json.Marshal of the map is fine; tests compare decoded maps).

Write MergeJSON(base, override) that returns a map[string]any. Invalid JSON is treated as {}.

Next: Auth Middleware