Options accepted by the JSON-LD processing algorithms.
as specified at https://www.w3.org/TR/json-ld11-api/#the-jsonldoptions-type
Additional options
Besides the standard JSON-LD options described in the specification, this implementation provides the following additional options:
:lowercase_language- When set totrue(default), language tags are automatically converted to lowercase during processing.:warn- Configures how warnings are handled during processing. Possible values::default- Uses the value from the application config (defaults to:log):ignore- Silently ignores warnings:raise- Raises an exception on warnings:log- Logs warnings using Loggertrue- Same as:defaultfalse- Same as:ignore- A function accepting a message string
The default warning behavior can be configured in your application config:
config :json_ld, warn: :log # or any other valid warning option, except :default:safe- When set totrue, processing fails with aJSON.LD.Errorwith codesafe modewherever the algorithms would otherwise drop data of the input without an error (default:false). A function is called in these places instead and decides itself. See the section on safe mode below.
Safe mode
The JSON-LD algorithms drop what they cannot interpret: a property the context does not define, a node whose identifier is not a valid IRI, a value with a language tag that is not well-formed. The RDF of such a document does not stand for all of the document. This matters wherever the RDF is taken for the document, above all when a digital signature is computed over the canonical form of the RDF: what is added to a signed document in such a place leaves its signature valid.
With safe: true processing fails in these places instead. The option is modelled on
the safe mode of jsonld.js, but the checks are not identical.
The expansion, and with it every function that expands its input, fails on
- a property that does not expand to an IRI or a keyword
- a free-floating value at the top level, in
@graphor in@included: a scalar, a value object, a list or a node object with nothing but an@id - a value object without a value but with other entries, and an object with nothing
but
@language - a key of a language, index, id or type map that has no value
- the value of a keyword that is not processed in a node object
The conversion to RDF fails in addition on
- a node identifier, type, property or graph name that is not a valid IRI, which includes a blank node as property
- a value that is not valid, like one with a language tag that is not well-formed, also as an item of a list
- a base direction, when
:rdf_directionis not set - a node identifier that is not part of any statement
The following are dropped in safe mode too:
nullvalues, empty arrays and empty objects@indexvalues, such as the keys of an index map- the order of the values of a property and duplicates among them, unless it is a list
- the digits of a number beyond the precision of a double
Give the option to the function that receives the original document. In
doc |> JSON.LD.expand() |> JSON.LD.to_rdf(safe: true) the expansion has dropped its
share already, when the conversion to RDF checks the rest. The paths a handler gets lead
into what the function received, too.
Safe mode asserts that the RDF stands for all of the document, not that the document
says what the RDF says. The context is part of the input: one that swaps the definitions
of two terms turns a document into a different one with the same RDF. An application
that verifies a signature over the RDF should go on with the RDF, or with what
JSON.LD.from_rdf/2 and a compaction with a context of its own make of it, and not
with the document as it was received.
Handlers
With a function as the value of the option, processing does not fail in these places.
The function is called with what is dropped and decides itself whether processing goes
on. See JSON.LD.SafeMode for the handlers and the codes they are called with.
Limitations
The :produce_generalized_rdf option is currently not supported due to lack of Generalized RDF
support in RDF.ex.
Summary
Types
@type t() :: %JSON.LD.Options{ base: String.t() | nil, compact_arrays: boolean(), compact_to_relative: boolean(), document_loader: nil, expand_context: map() | String.t() | nil, extract_all_scripts: boolean(), frame_expansion: boolean(), lowercase_language: boolean(), ordered: boolean(), processing_mode: String.t(), produce_generalized_rdf: boolean(), profile: String.t() | nil, rdf_direction: String.t() | nil, request_profile: String.t() | [String.t()] | nil, safe: boolean() | JSON.LD.SafeMode.handler(), use_native_types: boolean(), use_rdf_type: boolean(), warn: warn_method() }