(out: &mut String, value: &Value)
| 28 | } |
| 29 | |
| 30 | fn write_value(out: &mut String, value: &Value) { |
| 31 | match value { |
| 32 | Value::Null => out.push_str("null"), |
| 33 | Value::Bool(true) => out.push_str("true"), |
| 34 | Value::Bool(false) => out.push_str("false"), |
| 35 | Value::Number(n) => out.push_str(&n.to_string()), |
| 36 | Value::String(s) => write_json_string(out, s), |
| 37 | Value::Array(items) => { |
| 38 | out.push('['); |
| 39 | for (i, item) in items.iter().enumerate() { |
| 40 | if i > 0 { |
| 41 | out.push(','); |
| 42 | } |
| 43 | write_value(out, item); |
| 44 | } |
| 45 | out.push(']'); |
| 46 | } |
| 47 | Value::Object(map) => { |
| 48 | let mut keys: Vec<&String> = map.keys().collect(); |
| 49 | keys.sort_by(|a, b| a.encode_utf16().cmp(b.encode_utf16())); |
| 50 | out.push('{'); |
| 51 | for (i, key) in keys.iter().enumerate() { |
| 52 | if i > 0 { |
| 53 | out.push(','); |
| 54 | } |
| 55 | write_json_string(out, key); |
| 56 | out.push(':'); |
| 57 | write_value(out, &map[*key]); |
| 58 | } |
| 59 | out.push('}'); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /// Emit a JSON string with standard escaping. `serde_json` produces a valid, |
| 65 | /// minimally-escaped JSON string literal (quotes included), which matches JCS |
no test coverage detected