Converts the result to a JSON array of objects. Each row becomes a JSON object with column names as keys.
(&self)
| 209 | /// |
| 210 | /// Each row becomes a JSON object with column names as keys. |
| 211 | pub fn to_json_array(&self) -> Vec<Value> { |
| 212 | self.rows |
| 213 | .iter() |
| 214 | .map(|row| { |
| 215 | let mut obj = Map::new(); |
| 216 | for (i, col) in self.columns.iter().enumerate() { |
| 217 | obj.insert(col.clone(), row.get(i).cloned().unwrap_or(Value::Null)); |
| 218 | } |
| 219 | Value::Object(obj) |
| 220 | }) |
| 221 | .collect() |
| 222 | } |
| 223 | } |
no outgoing calls