/ sinks / sink-common / src / json.rs
json.rs
 1  use serde_json::Value;
 2  
 3  pub trait ValueExt {
 4      /// If `Self` is an array of objects, returns the associated vector of values.
 5      /// Returns `None` otherwise.
 6      fn as_array_of_objects(&self) -> Option<&Vec<Value>>;
 7  }
 8  
 9  impl ValueExt for Value {
10      fn as_array_of_objects(&self) -> Option<&Vec<Value>> {
11          let Some(values) = self.as_array() else {
12              return None;
13          };
14  
15          if values.iter().all(|v| v.is_object()) {
16              Some(values)
17          } else {
18              None
19          }
20      }
21  }