Small `serde_json::Value` whose re-serialization is order-stable (object keys are fixed and few).
(&mut self, depth: u8)
| 149 | /// Small `serde_json::Value` whose re-serialization is order-stable |
| 150 | /// (object keys are fixed and few). |
| 151 | fn json_value(&mut self, depth: u8) -> serde_json::Value { |
| 152 | use serde_json::Value; |
| 153 | match self.below(if depth == 0 { 4 } else { 6 }) { |
| 154 | 0 => Value::Null, |
| 155 | 1 => Value::Bool(self.boolean()), |
| 156 | 2 => Value::from(self.i32_small()), |
| 157 | 3 => Value::from(self.string()), |
| 158 | 4 => { |
| 159 | let n = self.below(3); |
| 160 | Value::Array((0..n).map(|_| self.json_value(depth - 1)).collect()) |
| 161 | } |
| 162 | _ => { |
| 163 | let mut map = serde_json::Map::new(); |
| 164 | map.insert("k0".into(), self.json_value(depth - 1)); |
| 165 | if self.boolean() { |
| 166 | map.insert("k1".into(), Value::from(self.string())); |
| 167 | } |
| 168 | Value::Object(map) |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | /// Like [`json_value`], but never a top-level JSON `null`. |
| 173 | /// |
| 174 | /// For an `Option<serde_json::Value>` field, serde collapses |
no test coverage detected