fn merge_json(
  mut fields: Map<String, Value>,
  json_key: String,
  json_val: Value,
) -> Map<String, Value> {
  let existing_val = fields.get_mut(&json_key).unwrap();
  match existing_val {
    Value::Object(existing_map) => {
      // append key:vals to the existing object
      if let Value::Object(json_val_map) = json_val {
        for (key, val) in json_val_map.into_iter() {
          existing_map.insert(key, val);
        }
      }
    }

    Value::Array(existing_vec) => {
      if let Value::Array(json_val_vec) = json_val {
        for val in json_val_vec.into_iter() {
          existing_vec.push(val);
        }
      }
    }

    _ => {
      // assumed to be a string
      fields.insert(json_key, json_val);
    }
  };

  fields
}
// Merges json_val into fields, where fields already has a value for json_key.
// If json_val is an object, then the key:val is appended to the existing object.
// If json_val is an array, then each item in the array is appended to the existing array.
Merges json_val into fields, where fields already has a value for json_key.
If json_val is an object, then the key:val is appended to the existing object.
If json_val is an array, then each item in the array is appended to the existing array.
Merges json_val into fields where fields already has a value for json_key . If json_val is an object then the key : val is appended to the existing object . If json_val is an array then each item in the array is appended to the existing array .
fn merge_json(
  mut fields: Map<String, Value>,
  json_key: String,
  json_val: Value,
) -> Map<String, Value> {
  let existing_val = fields.get_mut(&json_key).unwrap();
  match existing_val {
    Value::Object(existing_map) => {
      // append key:vals to the existing object
      if let Value::Object(json_val_map) = json_val {
        for (key, val) in json_val_map.into_iter() {
          existing_map.insert(key, val);
        }
      }
    }
    Value::Array(existing_vec) => {
      if let Value::Array(json_val_vec) = json_val {
        for val in json_val_vec.into_iter() {
          existing_vec.push(val);
        }
      }
    }
    _ => {
      // assumed to be a string
      fields.insert(json_key, json_val);
    }
  };
  fields
}
fn merge_json ( mut fields : Map < String , Value > , json_key : String , json_val : Value , ) -> Map < String , Value > { let existing_val = fields . get_mut ( & json_key ) . unwrap ( ) ; match existing_val { Value :: Object ( existing_map ) => { // append key:vals to the existing object if let Value :: Object ( json_val_map ) = json_val { for ( key , val ) in json_val_map . into_iter ( ) { existing_map . insert ( key , val ) ; } } } Value :: Array ( existing_vec ) => { if let Value :: Array ( json_val_vec ) = json_val { for val in json_val_vec . into_iter ( ) { existing_vec . push ( val ) ; } } } _ => { // assumed to be a string fields . insert ( json_key , json_val ) ; } } ; fields }
Merges json_val into fields, where fields already has a value for json_key.
Merges json_val into fields where fields already has a value for json_key .
fields
Map<String, Value>
json_key
String
json_val
Value
fields
Map<String, Value>
json_key
String
json_val
Value