pub fn merge_schema(a: &mut Value, b: &Value)
Expand description
Merges two JSON schemas represented as serde_json::Value
.
This function performs a recursive merge between two JSON objects. If an object has common keys, the values are merged recursively. If the value is not an object, it is directly overwritten.
§Arguments
a
- A mutable reference to the first JSON object (serde_json::Value::Object
).b
- A reference to the second JSON object (serde_json::Value::Object
) that will be merged with the first.
§Example
use serde_json::{json, Value};
let mut schema1 = json!({
"name": "John",
"age": 30,
});
let schema2 = json!({
"age": 31,
"city": "New York"
});
merge_schema(&mut schema1, &schema2);
assert_eq!(schema1, json!({
"name": "John",
"age": 31,
"city": "New York"
}));