Import: json
The json import enables a Sentinel policy to parse and access a JSON document.
json.unmarshal(obj)
Unmarshals the JSON object obj
into a native Sentinel structure.
All native JSON types can be represented perfectly as Sentinel native types.
// Typically the input for this would come from an external source.
config = json.unmarshal("{ \"foo\": 42 }")
config.foo // 42
config.bar // undefined (as usual for accessing a non-existent map key)
json.marshal(obj)
Marshals the Sentinel object obj
into a JSON object encoded as a string.
Sentinel's functions cannot be natively encoded, and will cause an error if it is present within the provided object.
Sentinel's undefined
cannot be natively encoded as JSON. If undefined
is supplied directly to marshal
, it will return undefined
. If undefined
is present within any map or list within the provided object, the associated
element will be removed prior to performing the JSON encoding.