Enum cedar_policy_core::entities::JSONValue
source · pub enum JSONValue {
ExprEscape {
__expr: SmolStr,
},
EntityEscape {
__entity: TypeAndId,
},
ExtnEscape {
__extn: FnAndArg,
},
Bool(bool),
Long(i64),
String(SmolStr),
Set(Vec<JSONValue>),
Record(HashMap<SmolStr, JSONValue>),
}
Expand description
The canonical JSON representation of a Cedar value.
Many Cedar values have a natural one-to-one mapping to and from JSON values.
Cedar values of some types, like entity references or extension values,
cannot easily be represented in JSON and thus are represented using the
__expr
, __entity
, or __extn
escapes.
For example, this is the JSON format for attribute values expected by
EntityJsonParser
, when schema-based parsing is not used.
Variants§
ExprEscape
Special JSON object with single reserved “__expr” key:
interpret the following string as a (restricted) Cedar expression.
Some escape (this or the following ones) is necessary for extension
values and entity references, but this __expr
escape could also be
used for any other values.
__expr
is deprecated (starting with the 1.2 release) and will be
removed in favor of __entity
and __extn
, which together cover all of
the use-cases where __expr
would have been necessary.
EntityEscape
Special JSON object with single reserved “__entity” key:
the following item should be a JSON object of the form
{ "type": "xxx", "id": "yyy" }
.
Some escape (this or __expr
, which is deprecated) is necessary for
entity references.
ExtnEscape
Special JSON object with single reserved “__extn” key:
the following item should be a JSON object of the form
{ "fn": "xxx", "arg": "yyy" }
.
Some escape (this or __expr
, which is deprecated) is necessary for
extension values.
Bool(bool)
JSON bool => Cedar bool
Long(i64)
JSON int => Cedar long (64-bit signed integer)
String(SmolStr)
JSON string => Cedar string
Set(Vec<JSONValue>)
JSON list => Cedar set; can contain any JSONValues, even heterogeneously
Record(HashMap<SmolStr, JSONValue>)
JSON object => Cedar record; must have string keys, but values can be any JSONValues, even heterogeneously
Implementations§
source§impl JSONValue
impl JSONValue
sourcepub fn into_expr(self) -> Result<RestrictedExpr, JsonDeserializationError>
pub fn into_expr(self) -> Result<RestrictedExpr, JsonDeserializationError>
Convert this JSONValue into a Cedar “restricted expression”
sourcepub fn from_expr(
expr: BorrowedRestrictedExpr<'_>
) -> Result<Self, JsonSerializationError>
pub fn from_expr( expr: BorrowedRestrictedExpr<'_> ) -> Result<Self, JsonSerializationError>
Convert a Cedar “restricted expression” into a JSONValue
.