Skip to main content

compact_value

Function compact_value 

Source
pub fn compact_value(
    active_ctx: &JsonLdContext,
    active_property: Option<&str>,
    value: &JsonLdValue,
) -> Result<JsonLdValue, CompactionError>
Expand description

Compact a JSON-LD value object.

Applies the W3C JSON-LD 1.1 Value Compaction algorithm: https://www.w3.org/TR/json-ld11-api/#value-compaction

§Compaction rules

  1. If the value is {"@value": v, "@type": "@json"} — keep as-is.
  2. If the value has @type and the active property’s term has a matching type mapping — drop the @type and @value wrapper.
  3. If the value has @language and the active property’s term has a matching language mapping — drop the wrapper.
  4. Plain string values without type/language — drop @value wrapper.
  5. Numeric and boolean values — return native JSON representation.

§Arguments

  • active_ctx — the active context
  • active_property — the property whose value is being compacted
  • value — the expanded value object