Skip to main content

ferrin_spec/
json.rs

1//! JSON value aliases shared by the whole specification.
2//!
3//! Ferrin uses `serde_json` types directly instead of defining its own JSON
4//! model. The aliases exist so that the specification reads uniformly and so
5//! that a future change of representation touches one place.
6
7/// A JSON value.
8pub type JsonValue = serde_json::Value;
9
10/// A JSON object (string keys, insertion order preserved).
11pub type JsonObject = serde_json::Map<String, JsonValue>;
12
13/// Returns `true` when an optional JSON object is `None` or empty.
14///
15/// Used with `#[serde(skip_serializing_if = "...")]` so that empty option
16/// maps do not appear in serialized output.
17#[must_use]
18pub fn is_none_or_empty_object(value: &Option<JsonObject>) -> bool {
19    value.as_ref().is_none_or(JsonObject::is_empty)
20}