Copyright © 2020-2026 World Wide Web Consortium. W3C® liability, trademark and permissive document license rules apply.
CBOR is a compact binary data serialization and messaging format. This specification defines CBOR-LD 1.0, a CBOR-based format to serialize Linked Data. The encoding is designed to leverage the existing JSON-LD ecosystem, which is deployed on hundreds of millions of systems today, to provide a compact serialization format for those seeking efficient encoding schemes for Linked Data. By utilizing semantic compression schemes, compression ratios in excess of 60% better than generalized compression schemes are possible. This format is primarily intended to be a way to use Linked Data in storage and bandwidth constrained programming environments, to build interoperable semantic wire-level protocols, and to efficiently store Linked Data in CBOR-based storage engines.
This section describes the status of this document at the time of its publication. A list of current W3C publications and the latest revision of this technical report can be found in the W3C standards and drafts index.
This document is experimental.
There is a reference implementation that is capable of demonstrating the features described in this document.
This document was published by the JSON-LD Working Group as a Working Draft using the Recommendation track.
Publication as a Working Draft does not imply endorsement by W3C and its Members.
This is a draft document and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to cite this document as other than a work in progress.
This document was produced by a group operating under the W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent that the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This document is governed by the 18 August 2025 W3C Process Document.
This section is non-normative.
CBOR is a compact binary data serialization and messaging format. This specification defines CBOR-LD 1.0, a CBOR-based format to serialize Linked Data. The encoding is designed to leverage the existing JSON-LD ecosystem, which is deployed on hundreds of millions of systems today, to provide a compact serialization format for those seeking efficient encoding schemes for Linked Data. By utilizing semantic compression schemes, compression ratios in excess of 60% better than generalized compression schemes are possible. This format is primarily intended to be a way to use Linked Data in storage and bandwidth constrained programming environments, to build interoperable semantic wire-level protocols, and to efficiently store Linked Data in CBOR-based storage engines.
This section is non-normative.
This document is a detailed specification for a serialization of Linked Data in CBOR. The document is primarily intended for the following audiences:
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.
The key word MUST in this document is to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, it appears in all capitals, as shown here.
This section is non-normative.
There are a number of ways that one may participate in the development of this specification:
This section is non-normative.
CBOR-LD satisfies the following design goals:
Similarly, the following are non-goals.
The following minefields have been identified while working on this specification:
This section is non-normative.
At a high level, CBOR-LD is a compact, binary serialization for JSON-LD that allows the following mechanisms for additional compression:
Codecs are the basic primitive for compressing typed values in a generic way. Semantic compression is for compressing JSON-LD terms. Registry dictionaries are for compressing typed values in a use-case-specific way. Each of these is optional — CBOR-LD can be used with any, all, or none of these compression strategies. Taken together, the set of these strategies that is used for a particular use case is known as a processing model.
This section is non-normative.
Semantic compression is a powerful tool for creating compact CBOR-LD payloads. The core idea is to use the information content of external JSON-LD context objects to compress JSON-LD terms. These external context objects are available to both the creator and the consumer of the payload, so this is done in an invertible way.
The general semantic compression process is to take a JSON-LD Document and do the following:
@context values in JSON-LD document
that reference contexts via URIs; embedded context values cannot be compressed).
CBOR-LD payloads need to be identifiable as such at the binary level. CBOR natively supports this via its "tag" feature — a header value in the binary data that describes the rest of the payload via a global registry.
The CBOR tag 0xCB1D (tag value 51997) has been registered
in the
IANA CBOR tag registry to be used for CBOR-LD. The data that immediately
follows this tag value identifies the registry entry that was used to create
the compressed payload.
CBOR-LD payloads MUST be structured such that the item tagged with tag 0xCB1D is
a two-element array, and the first element MUST be a
major type 0 integer.
This integer is a CBOR-LD Registry Entry ID. The binary structure is tag([registryEntryId, payload]).
The value of the CBOR-LD Registry Entry ID is then used to look up a CBOR-LD Registry Entry in the CBOR-LD Registry.
To enable unbounded extension of possible use cases for CBOR-LD that require different compression table material for consumption while working with a single CBOR tag value, we define the following.
The CBOR-LD Registry is a global list that provides consumers of CBOR-LD payloads the information they need to reconstruct the term-codec map required for decompression. A CBOR-LD Registry Entry contains the following:
Registry Entry ID: A positive integer.
Use Case: The type of CBOR-LD payload this entry is to be used for.
typeTables: An array containing the registry dictionaries that are to be used with this
registry entry.
processingModel: what processing model is used for this registry entry. A processing model
specifies the following:
default processing model uses semantic compression and includes the codecs specified in this document.
provisional: a boolean indicating whether the entry is provisional. Provisional entries
may change or be removed.
The string "callerProvidedTable", may appear in typeTables, denoting that for this use case, a
Type Table is required which is not globally defined.
The current CBOR-LD Registry can be found here.
To register an entry, follow the instructions in the README. The registry is owned by the W3C JSON-LD Community Group.
This algorithm takes a map typeTable, an integer registryEntryId, and a JSON-LD
document jsonldDocument as inputs, and returns a hexadecimal string cborldBytes.
prefix to the result of passing registryEntryId to
5.6.1 Get CBOR Tag Structure Algorithm.
state to an empty map.
registryEntryId requires semantic compression:
state.strategy to "compression".
state.typeTable to typeTable.
state.registryEntryId to registryEntryId.
state to the result of passing state to
5.2.1 Initialize Conversion Algorithm.
output to the result of passing state and jsonldDocument
as inputDocument to 5.2.2 Convert Document Algorithm.
suffix to the CBOR encoding of output.
suffix to the CBOR encoding of jsonldDocument.
cborldBytes to a hexidecimal encoding of prefix prepended to suffix.
cborldBytes.
This algorithm takes a CBOR-LD payload cborldBytes, and returns a JSON-LD document jsonldDocument.
result to the result of passing cborldBytes to
5.6.2 Get Registry Entry ID Algorithm.
state.registryEntryId to result.registryEntryId and suffix to result.suffix.
state to an empty map.
state.registryEntryId uses semantic compression:
state.strategy to "decompression".
type: map in the typeTables array in the CBOR-LD Varint Registry Entry
associated with registryEntryId, add that entry to state.typeTable, and set the value of type
in state.reverseTypeTable to inverseMap, where inverseMap is map with the mapping inverted.
state to the result of passing state to
5.2.1 Initialize Conversion Algorithm.
input to the result of decoding suffix from bytes to a map.
jsonldDocument to the result of passing state and input as inputDocuments
to 5.2.2 Convert Document Algorithm.
jsonldDocument to the result of parsing cborldBytes.
jsonldDocument.
The algorithms in this section describe the behavior of a "converter" for abstractly converting inputs between data forms. When used in conjunction with a "strategy", such as the "compression" and "decompression" strategies defined later in this section, these algorithms can be instantiated to convert between concrete data forms. The "compression" strategy converts from JSON-LD to CBOR-LD, while the "decompression" strategy converts from CBOR-LD to JSON-LD.
This algorithm takes and returns a map state.
state to the result of passing state to
5.4.1 Initialize Context Loader Algorithm.
state.initialActiveContext to the result of passing empty maps termMap and
previousActiveContext to 5.3.1 Initialize Active Context Algorithm.
state.typesEncodedAsBytes to an empty set.
state.typesEncodedAsBytes.
state.
This algorithm takes a map state and a map or array of
maps inputDocuments, and returns a map containing a map state and a map or
array of maps outputMaps.
inputDocuments is an array, set inputs to inputDocuments. Otherwise, set inputs
to [inputDocuments].
outputMaps to an empty array.
input in inputs:
output to an empty map.
result to the result of passing state, input, output, and
state.initialActiveContext as activeContext to
5.2.3 General Conversion Algorithm.
result.output to outputMaps.
state to result.state.
inputDocuments is an array, return outputMaps. Otherwise, return the
first element of outputMaps.
This algorithm takes maps input, output, state, and activeContext
as inputs, and returns a map containing maps state and output.
state.strategy is set to "compression":
contextConversionResult to the result of
5.2.5.1 Convert Contexts for Compression Algorithm, passing
state, activeContext, input, and output.
activeContext to contextConversionResult.activeContext, output
to contextConversionResult.output, and state to contextConversionResult.state.
activeContext to
result.activeContext and state to result.state of result resulting from
5.2.6.1 Convert Contexts for Decompression Algorithm, passing state,
activeContext, input, and output.
state.strategy is set to "compression", set state to result.state and
objectTypes to result.objectTypes for result resulting from
5.2.5.4 Get Object Types for Compression Algorithm, passing state,
activeContext, input, and output.
state to result.state and objectTypes to result.objectTypes
for result resulting from 5.2.6.4 Get Object Types for Decompression Algorithm,
passing state, activeContext, input, and output.
activeContext to the result of passing activeContext and objectTypes to
5.3.4 Apply Type Scoped Contexts Algorithm.
state.strategy is set to "compression", set state to result.state and
termEntries to result.termEntries for result resulting from
5.2.5.3 Get Input Entries for Compression Algorithm, passing state,
input, and activeContext.
state to result.state, output to result.output,
and termEntries to result.termEntries for result resulting from
5.2.6.3 Get Input Entries for Decompression Algorithm,
passing state, input, output, and activeContext.
[termInfo, value] in termEntries:
term to termInfo.term.
valueActiveContext to the result of passing activeContext and term to
5.3.3 Apply Property Scoped Contexts Algorithm.
plural to the value of termInfo.plural and termType to the value of @type
in termInfo.def.
plural is set to true, set values to the value of value. Otherwise, set values to
an array containing the value of value as a single element.
outputs to an empty array.
unconvertedValue in values:
result to the result of 5.2.4 Convert Value Algorithm,
passing state, termType, unconvertedValue as value, and valueActiveContext
as activeContext.
state to result.state and add result.output to outputs.
plural is set to true, set outputValues to outputs. Otherwise, set outputValues
to the first element of outputs.
state.strategy is set to "compression", set the value of termInfo.termId to map to
outputValues in output. Otherwise, set the value of termInfo.term to map to outputValues
in output.
result to be an empty map.
result.state to state and result.output to output.
result.
This algorithm takes maps state, activeContext, termInfo, and values value and termType.
It returns a result object containing maps state and output.
value is null, return null.
state.strategy is set to "compression", set output to the result of passing state, termType,
termInfo, and value to 5.2.5.2 Convert Value for Compression Algorithm.
output to the result of passing state, termType,
termInfo, and value to 5.2.6.2 Convert Value for Decompression Algorithm.
output is defined, return result, a map contatining state and output.
value is an array:
outputs to be an empty array.
element of value:
result be the result of 5.2.4 Convert Value Algorithm, passing activeContext, state,
termInfo, termType, and element as value. Set state to result.state and add result.output
to outputs.
result to be an empty map. Set result.state to state and result.output to outputs.
result.
output to an empty map.
result to the result of 5.2.3 General Conversion Algorithm, passing state,
activeContext, value as input, and output.
result.
The algorithms in this section define the "compression" strategy to be used with the "conversion" algorithms defined previously to convert JSON-LD to CBOR-LD.
This algorithm takes maps state, activeContext, input, and output,
and returns a map result containing maps output, state, and activeContext.
applyEmbeddedResult to the result of 5.3.2 Apply Embedded Contexts Algorithm,
passing state, activeContext, and input.
activeContext to applyEmbeddedResult.activeContext and state to
applyEmbeddedResult.state.
input:
result to an empty map.
result.state to state and result.activeContext to activeContext.
result.
context to the value of "@context" in input.
encodedContexts to an empty array.
context is an array, set isArray to true and contexts to context.
Otherwise, set isArray to false and contexts to [context].
contextValue in contexts:
encoderData to the result of 5.5.1.1 Create Context Encoder, passing
state.typeTable and contextValue.
encoderData is an empty map, add contextValue to encodedContexts.
encoderData to encodedContexts.
isArray is true, set id to the value of "@context" in state.keywordsMap plus 1
and set the value of id in output to encodedContexts.
id to the value of "@context" in state.keywordMap and set the value of
id in output to the first element of encodedContexts.
result.output to output, result.state to state, and result.activeContext
to activeContext.
result.
This algorithm takes maps state and termInfo, and values valueToEncode and termType,
and returns a map encoderData.
valueToEncode is an object, return.
result to the result of 5.5.2.1 Create Value Encoder, passing
state, termInfo, valueToToEncode, and termType.
result.
This algorithm takes maps state, activeContext, and input, and returns a map state and an array entries.
entries as an empty array.
keys to the keys of input, sorted lexicographically.
key in keys:
key is "@context", continue.
value to the value of key in input.
value is an array, set plural to true. Otherwise, set plural to false.
key does not have an entry in state.termToId, set termId to key.
plural is true, set termId to the value of key in state.termToId plus 1.
termId to the value of key in state.termToId.
activeContext.termMap has an entry for key, set definition to the value of key in
activeContext.termMap. Otherwise, set definition to an empty map.
entryTerm to be a new map.
entryTerm to be the value of key. Add termId, plural, and definition
to entryTerm.
entry with two elements, entryTerm and value.
entry to entries.
result containing entries and state.
This algorithm takes maps activeContext and input, and returns a set
objectTypes.
objectTypes to be an empty set.
term in activeContext.typeTerms:
term has an entry in input:
types to the value of term in input.
types to objectTypes.
objectTypes.
The algorithms in this section define the "decompression" strategy to be used with the "conversion" algorithms defined previously to convert CBOR-LD to JSON-LD.
This algorithm takes maps state, activeContext, input, and output, and returns a map
result containing maps output, state, and activeContext.
decoderData to the result of 5.5.1.3 Create Context Decoder, passing state.reverseTypeTable.
contextTermId to the value of "@context" in state.keywordsMap.
contextTermId has an entry in input, set the value of
"@context" in output to the result of 5.5.1.4 Decode Context, passing decoderData and
the value of contextTermId in input as value.
contextTermIdPlural to the value of contextTermId plus 1.
contextTermIdPlural has an entry in input:
contextTermId also had an entry in input during the previous check, throw an
ERR_INVALID_ENCODED_CONTEXT error.
encodedContexts to be the value of contextTermIdPlural in input. If encodedContexts is
not an array, throw an ERR_INVALID_ENCODED_CONTEXT error.
contexts to be an empty array.
valueToDecode in encodedContexts, add the result of passing decoderData and valueToDecode
as value to 5.5.1.4 Decode Context to contexts.
output to contexts.
embeddedContextResult to the result of 5.3.2 Apply Embedded Contexts Algorithm, passing
activeContext, output as input, and state.
result to an empty map.
result.state to embeddedContextResult.state and result.activeContext to
embeddedContextResult.activeContext.
result.
This algorithm takes maps state and termInfo, and values termType and valueToDecode, and returns a value
decodedValue.
value is a map, return.
decoderData to the result of 5.5.2.3 Create Value Decoder, passing valueToDecode,
state, termInfo, and termType.
decodedValue to the result of 5.5.2.4 Decode Value, passing decoderData.
decodedValue.
This algorithm takes maps state, activeContext, and input, and returns a map state and an array
entries.
entries to an empty array.
key and value in input:
key is the value of "@context" in state.keywordsMap or that value plus 1, continue.
key is a string, set plural to false and term to key.
key is odd, set plural to true. Otherwise, set plural to false.
plural is true, set term to the value of id minus 1 in state.idToTerm.
If that value does not have an entry, throw an error ERR_UNKNOWN_CBORLD_TERM_ID.
term to the value of id in state.idToTerm. If that value does not have
an entry, throw an error ERR_UNKNOWN_CBORLD_TERM_ID.
definition to the value of term in activeContext.termMap.
entryTerm to be a new map.
entryTerm to be the value of key. Add term, plural, and definition
to entryTerm.
entry with two elements, entryTerm and value.
entry to entries.
entries by the value of term in each element of entries.
result containing entries and state.
This algorithm takes maps state, activeContext, input as inputs, and
returns a map state and a set objectTypes.
objectTypes to be an empty set.
term in activeContext.typeTerms:
term does not have an entry in state.termToId, set termId to term.
termId to the value of term in state.termToId.
termId nor termId plus 1 are present in input, continue.
termId is present in input, set value to the value of termId in input.
value to the value of termId plus 1 in input.
key is a string, set plural to false and term to key.
key is odd, set plural to true. Otherwise, set plural to false.
plural is true, set term to the value of id minus 1 in state.idToTerm.
If that value does not have an entry, throw an error ERR_UNKNOWN_CBORLD_TERM_ID.
term to the value of id in state.idToTerm. If that value does not have
an entry, throw an error ERR_UNKNOWN_CBORLD_TERM_ID.
definition to the value of term in activeContext.termMap.
termInfo to be a new map.
term, termId, plural, and definition to termInfo.
value is not an array, set values to be an array containing as a single element value.
Otherwise, set values to the value of value.
value in values:
decoderData to the result of 5.5.2.3 Create Value Decoder, passing value,
termInfo, state, and "@vocab" as termType.
decoderData exists, add the result of 5.5.2.4 Decode Value, passing decoderData, to `objectTypes.
value to objectTypes.
objectTypes.
The algorithms in this section describe how to determine what components of the context documents associated with a JSON-LD document are in use at any point during compression or decompression. These algorithms include how to apply embedded, type-scoped, and property-scoped contexts with CBOR-LD. This is in contrast to the Context Loading algorithms defined later in this specification, which describe how to construct the mappings from terms to integers that are the core CBOR-LD compression technique. Together, the Active Context Processing and Context Loading algorithms specify how JSON-LD context documents should be processed when converting to and from CBOR-LD.
This algorithm takes maps previousActiveContext and termMap,
and returns a map activeContext. It updates the active context
in use and finds all aliases for '@type'.
activeContext to a new map.
activeContext.previousActiveContext to previousActiveContext.
activeContext.termMap to termMap.
activeContext.typeTerms to the array ['@type'].
[term, def] in termMap:
def is "@type", add term to activeContext.typeTerms.
activeContext.
This algorithm takes maps state, activeContext, and input as inputs, and
returns a map result containing maps state and activeContext.
termMapUpdateResult to the result of passing state, activeContext.termMap as
activeTermMap, and the value of '@context' in input as contexts to
5.3.5 Update Term Map Algorithm.
state to termMapUpdateResult.state.
termMap to termMapUpdateResult.activeTermMap.
newActiveContext to the result of 5.3.1 Initialize Active Context Algorithm,
passing termMap and activeContext as previousActiveContext.
result to be a new map, and set result.activeContext to newActiveContext and
result.state to state.
result.
This algorithm takes maps state, activeContext, and a string term as inputs and
returns a map result containing maps state and activeContext.
revertedTermMap to the result of 5.3.6 Revert Term Map Algorithm,
passing activeContext.
termDef to the value of term in activeContext.termMap. Set contexts to the value of
"@context" in termDef.
termMapUpdateResult to the result of passing state, revertedTermMap as
activeTermMap, true as propertyScope, and contexts to
5.3.5 Update Term Map Algorithm.
state to termMapUpdateResult.state.
termMap to termMapUpdateResult.activeTermMap.
newActiveContext to the result of 5.3.1 Initialize Active Context Algorithm,
passing termMap and activeContext as previousActiveContext.
result to be a new map, and set result.activeContext to newActiveContext and
result.state to state.
result.
This algorithm takes maps state, activeContext ,and a set objectTypes as inputs, and
returns a map result containing maps state and activeContext.
objectTypesSorted to an empty array.
objectTypes and add the elements to
objectTypesSorted in order.
newTermMap to activeContext.termMap.
type in objectTypesSorted:
typeDef to the value of type in newTermMap. Set contexts to the value of
"@context" in typeDef.
termMapUpdateResult to the result of passing state, newTermMap as
activeTermMap, contexts, and true as typeScope to
5.3.5 Update Term Map Algorithm.
state to termMapUpdateResult.state and newTermMap to
termMapUpdateResult.activeTermMap.
newActiveContext to the result of 5.3.1 Initialize Active Context Algorithm,
passing newTermMap as termMap and activeContext as previousActiveContext.
result to be a new map, and set result.activeContext to newActiveContext and
result.state to state.
result.
This algorithm takes maps state, activeTermMap, and map or array contexts as well as booleans typeScope
and propertyScope, both of which default to false if not provided, as inputs. It returns maps state
and activeTermMap.
contexts is not an array, set contexts to be an array with the previous value of contexts
as its sole element.
allowProtectedOverride to the value of propertyScope.
propagateDefault to the negation of the value of typeScope.
contextIdentifier in contexts:
loadResult to the result of 5.4.2 Load Context Algorithm, passing state and
contextIdentifier.
entry to loadResult.entry, context to entry.context, and state to loadResult.state.
@propagate appears in context, set propagate to the value of @propagate in context.
Otherwise, set propagate to the value of propagateDefault.
newTermMap to be an empty map. For [key, value] in entry.termMap:
value into a new map newValue and add propagate
to newValue.
key in newTermMap to newValue.
term, activeDef] in activeTermMap:
def be the value of term in newTermMap.
def is defined:
protected in activeDef is true:
allowProtectedOverride is set to false and def is not identical to activeDef,
throw an error ERR_PROTECTED_TERM_REDEFINITION.
term in newTermMap to a map containing the values from activeDef
and propagate set to the value of def.propagate.
term appears in context, set the value of term in newTermMap to
a map containing all values from activeDef.
activeTermMap to the value of newTermMap.
result to be an empty map.
result.state to state and result.activeTermMap to activeTermMap.
result.
This algorithm takes as input a map activeContext, and returns a map
newTermMap.
newTermMap to an empty map.
nonPropagatingTerms to an empty array.
[term, def] in activeContext:
def.propagate is set to false, add term to nonPropagatingTerms
and proceed to the next iteration of this loop.
term in newTermMap to def.
term in nonPropagatingTerms:
currentContext to activeContext.previousActiveContext.
def to the value of term in currentContext.termMap.
def is not undefined and def.propagate is set to false:
currentContext to activeContext.previousActiveContext.
def to the value of term in currentContext.termMap.
def is not undefined, set the value of term in newTermMap to def.
newTermMap.
The algorithms in this section define how to construct the mappings between terms and integers that are used as the core CBOR-LD compression technique.
This algorithm takes and returns a map state.
state.contextMap to a new map.
state.nextTermId to 100.
state.keywordsMap to the following map of JSON-LD keywords to their associated
integer values:
{
'@context' => 0,
'@type' => 2,
'@id' => 4,
'@value' => 6,
'@direction' => 8,
'@graph' => 10,
'@included' => 12,
'@index' => 14,
'@json' => 16,
'@language' => 18,
'@list' => 20,
'@nest' => 22,
'@reverse' => 24,
'@base' => 26,
'@container' => 28,
'@default' => 30,
'@embed' => 32,
'@explicit' => 34,
'@none' => 36,
'@omitDefault' => 38,
'@prefix' => 40,
'@preserve' => 42,
'@protected' => 44,
'@requireAll' => 46,
'@set' => 48,
'@version' => 50,
'@vocab' => 52,
'@propagate' => 54
}
state.keywordsMap to state.termToId.
state.strategy is set to "decompression", set state.idToTerm to the reverse map
of state.termToId (i.e., a map from integers to JSON-LD keywords).
state.
This algorithm takes a map state and a context map or URL contextIdentifier, and returns
result, a map containing maps state and entry.
state.contextMap has an entry for contextIdentifier:
result to an empty map.
result.state to state.
result.entry to the value of contextIdentifier in state.contextMap.
result.
context is a string:
context to the value
of "@context" in that object.
contextUrl to the value of contextIdentifier.
context to contextIdentifier.
result to the result of 5.4.3 Add Context Algorithm, passing
state, context, and contextUrl if set.
result.
This algorithm takes a map state, a context object context, and a context URL contextUrl,
and returns result, a map containing maps state and entry.
context has an entry "@import":
importUrl to the value of "@import" in `context.
state.contextMap does not have an entry for importUrl:
importUrl and set importContext to the value of
"@context" in that object.
importedContextAdditionResult to the result of 5.4.3 Add Context Algorithm,
passing state, importContext as context, and importUrl as contextUrl.
state to importedContextAdditionResult.state and importEntry to
importedContextAdditionResult.entry.
importEntry to the value of importUrl in state.contextMap.
context to a map containing all entries from context as well as importEntry.context.
termMap to an empty map.
entry to be an object containing context and termMap.
sortedTerms to the result of sorting the keys in context in lexicographic order.
isProtected to true if "@protected" has an entry in context and false otherwise.
term in sortedTerms:
term has an entry in state.keywordsMap, proceed to the next iteration of this loop.
definition to the value of term in context.
definition is null, proceed to the next iteration of this loop.
definition is a string:
newDefinition to an empty map.
newDefinition to definition.
definition to newDefinition.
protected in definition to isProtected.
term in termMap to definition.
term does not have an entry in state.termToId:
termId to state.nextTermId.
state.nextTermId by 2.
term in state.termToId to termId.
termId in state.idToTerm to term.
contextUrl is defined, set the value of contextUrl in
state.contextMap to entry.
context in state.contextMap
to entry.
result to be an empty map.
result.state to state and result.entry to entry.
result.
The codecs in this section specify exactly how individual values in JSON-LD should be converted to CBOR and vice versa. They are used by the algorithms in the previous section, and allow CBOR-LD to efficiently encode both primitive and non-primitive types as CBOR.
This algorithm takes a map typeTable and a value contextValue and
returns a map encoderData.
encoderData to an empty map.
contextValue is not a string, return.
contextTable to the value of "context" in typeTable.
encoderData.context to contextValue and encoderData.contextTable to
contextTable.
encoderData.
This algorithm takes a map encoderData, and returns CBOR binary data.
encoderData.context has an entry in encoderData.contextTable, return a CBOR encoding
of the value of encoderData.context in encoderData as a Major Type 0 (unsigned integer) object.
encoderData.context as a Major Type 3
(text string) object.
This algorithm takes a map reverseTypeTable, and
returns a map encoderData.
reverseContextTable to the value of "context" in reverseTypeTable.
decoderData to an empty map.
decoderData.reverseContextTable to the value of reverseContextTable and
return decoderData.
This algorithm takes a map decoderData and a value value, and returns a value.
value is not a number, return value.
decoderData.reverseContextTable has an entry for value, return
the value of that entry.
This algorithm takes maps state and termInfo, and values
termType and valueToEncode, and returns a map encoderData or valueToEncode.
isUrl to false.
termInfo.term is "@id" or "@type", set isUrl to true.
termInfo.def is "@id" or "@type", set
isUrl to true.
termType is "@id" or "@vocab", set isUrl to true.
isUrl is true, set tableType to "url".
termType is defined, set tableType to termType.
tableType to "none".
state.typeTable has an entry for tableType:
subTable to the value of tableType in state.typeTable.
subTable has an entry for valueToEncode:
intValue to the value of valueToEncode in subTable. Set includeSign to false.
state.typesEncodedAsBytes has an entry for tableType, set convertToBytes to true.
Otherwise, set convertToBytes to false.
tableType is not "none" and valueToEncode is an integer:
intValue to the value of valueToEncode.
convertToBytes and includeSign to true.
intValue is defined:
encoderData to an empty map.
encoderData.intValue to the value of intValue, encoderData.convertToBytes to
the value of convertToBytes, and encoderData.includeSign to the value of includeSign.
encoderData.
tableType has an entry in state.processingModeTypeEncoders, set encoderData to the result of
calling the Create Encoder algorithm associated with that entry's codec.
encoderData is defined, return encoderData.
valueToEncode.
This algorithm takes a map encoderData, and returns CBOR binary data.
encoderData.convertToBytes is true:
bytes to the result of converting intValue to bytes, using the value of includeSign to
determine whether the binary representation of the integer should be signed or unsigned.
bytes as a Major Type 2 (byte string) object.
intValue as a Major Type 0 (unsigned integer) object.
This algorithm takes maps state and termInfo, and values
termType and valueToDecode, and returns a map decoderData.
isUrl to false.
termInfo.term is "@id" or "@type", set isUrl to true.
termInfo.def is "@id" or "@type", set
isUrl to true.
termType is "@id" or "@vocab", set isUrl to true.
isUrl is true, set tableType to "url".
termType is defined, set tableType to termType.
tableType to "none".
state.reverseTypeTable has an entry for tableType:
subTable to the value of tableType in state.reverseTypeTable.
useTable to false.
valueToDecode is a byte array and state.typesEncodedAsBytes has an entry
for tableType:
useTable to true.
intValue to the unsigned integer conversion of the valueToDecode bytes.
valueToDecode is an integer and state.typesEncodedAsBytes does not
have an entry for tableType:
useTable to true.
intValue to valueToDecode.
useTable is true:
intValue is not in subTable, throw an error ERR_UNKNOWN_COMPRESSED_VALUE.
decoded to the value of intValue in subTable.
valueToDecode is a byte array and tableType is not "none", set
decoded to the integer conversion of valueToDecode.
decoded is defined, initialize decoderData to an empty map, set decoderData.decoded to
the value of decoded, and return decoderData.
tableType has an entry in state.processingModeTypeDecoders, set DecoderData to the result of
calling the Create Decoder algorithm associated with that entry's codec.
decoderData is defined, return decoderData.
valueToDecode is not an array, initialize decoderData to an empty map, set
decoderData.decoded to valueToDecode, and return decoderData.
This algorithm takes a map decoderData, and returns a value.
decoderData.decoded.
The URL Codec compresses URL values based on the scheme of the value. URLs are encoded as arrays, where the first integer denotes the scheme of the URL. The codec first checks whether the value matches a known JSON-LD term identifier, encoding it as a simple integer if so. Otherwise it delegates to one of the following URI-scheme-specific sub-codecs based on the URI scheme of the value.
The URL Scheme Table maps URI scheme prefixes to their associated compressed integer identifiers. Implementations that use the URL codec MUST use the following table. The URL Scheme Reverse Table is the inversion of this table (i.e. a map from integer to scheme prefix string).
| URI Scheme Prefix | Integer Identifier |
|---|---|
http:// | 1 |
https:// | 2 |
urn:uuid: | 3 |
data: | 4 |
did:v1:nym: | 1024 |
did:key: | 1025 |
This algorithm takes maps state, termInfo, and a
string valueToEncode, and returns an encoder object or
undefined.
valueToEncode is not a string, throw an
ERR_UNSUPPORTED_JSON_TYPE error.
termId to the result of looking up
valueToEncode in state.termToId.
termId is an integer, return an encoder that, when
invoked via 5.5.3.3 Encode URL, encodes termId as
a Major Type 0 (unsigned integer) CBOR item.
valueToEncode.
If parsing fails (the value is not a valid URI), return
undefined.
scheme to the longest matching prefix of
valueToEncode that appears in the URL Scheme Table.
scheme starts with "https" or
"http", return the result of
5.5.3.6.1 Create HTTP URL Encoder passing
valueToEncode and scheme.
scheme is "urn:uuid", return the result of
5.5.3.7.1 Create UUID URN Encoder passing
valueToEncode.
scheme is "data", return the result of
5.5.3.8.1 Create Data URL Encoder passing
valueToEncode.
scheme is "did:v1:nym" or
"did:key", return the result of
5.5.3.9.1 Create Base58 DID URL Encoder passing
valueToEncode and scheme.
undefined (no compression possible for this URI).
This algorithm takes an encoder object produced by 5.5.3.2 Create URL Encoder, and returns CBOR binary data.
termId as a Major Type 0 (unsigned integer) object.
encode method of the appropriate
URI-scheme sub-encoder and return the resulting CBOR binary data.
This algorithm takes maps state, termInfo, and a
value valueToDecode, and returns a decoder object or
undefined.
valueToDecode is a string, return undefined
(value is already an uncompressed URL string; pass through).
valueToDecode is an array:
schemeId to the first element of
valueToDecode.
scheme to the value of schemeId in the
URL Scheme Reverse Table.
scheme is "http://" or
"https://", return the result of
5.5.3.6.3 Create HTTP URL Decoder passing
valueToDecode.
scheme is "urn:uuid:", return the result of
5.5.3.7.3 Create UUID URN Decoder passing
valueToDecode.
scheme is "data:", return the result of
5.5.3.8.3 Create Data URL Decoder passing
valueToDecode.
scheme is "did:v1:nym:" or
"did:key:", return the result of
5.5.3.9.4 Create Base58 DID URL Decoder passing
valueToDecode.
ERR_UNKNOWN_COMPRESSED_VALUE error.
valueToDecode is an integer, set term to the
result of looking up valueToDecode in
state.idToTerm and return a decoder whose
5.5.3.5 Decode URL invocation returns term.
undefined.
This algorithm takes a decoder object produced by 5.5.3.4 Create URL Decoder, and returns a string value.
term string.
decode method of the appropriate
URI-scheme sub-decoder and return the resulting string.
The HTTP URL Codec handles values whose URI scheme is
http:// or https://. An encoded HTTP URL is
represented as a two-element CBOR array
[schemeId, remainder] where schemeId is the
integer from the URL Scheme Table and remainder is
the scheme-stripped portion of the URL as a text string.
This algorithm takes a string value and a string
scheme (either "https://" or
"http://"), and returns an encoder object or
undefined.
value starts with "https://", set
scheme to "https://".
value starts with "http://", set
scheme to "http://".
undefined.
value and
scheme.
This algorithm takes an encoder object from 5.5.3.6.1 Create HTTP URL Encoder, and returns CBOR binary data.
schemeId to the value of encoderData.scheme
in the URL Scheme Table.
rest to the substring of encoderData.value
beginning after encoderData.scheme.
[schemeId, rest]: Major Type 4 (array) containing a
Major Type 0 (unsigned integer) item followed by a Major Type 3
(text string) item.
This algorithm takes a CBOR array valueToDecode, and
returns a decoder object or undefined.
valueToDecode has exactly two elements and the second
element is a text string:
scheme to the value of valueToDecode[0]
in the URL Scheme Reverse Table.
scheme.
undefined.
This algorithm takes a decoder object from
5.5.3.6.3 Create HTTP URL Decoder and a CBOR array
valueToDecode, and returns a string.
decoderData.scheme and
valueToDecode[1].
The UUID URN Codec handles values whose URI scheme is
urn:uuid:. An encoded UUID URN is a two-element CBOR array
[3, uuidValue] where uuidValue is either a
16-byte Major Type 2 (byte string) representing the UUID in binary form
(when the UUID string is all lowercase), or a Major Type 3 (text string)
containing the UUID value verbatim (when the casing cannot be
round-tripped through binary form).
This algorithm takes a string value, and returns an encoder
object or undefined.
value does not start with "urn:uuid:",
return undefined.
value.
This algorithm takes an encoder object, and returns CBOR binary data.
schemeId to 3 (the entry for
"urn:uuid:" in the URL Scheme Table).
rest to the substring of encoderData.value
beginning after "urn:uuid:".
rest is entirely lowercase:
uuidBytes to the 16-byte binary representation of the
UUID obtained by parsing rest according to
[RFC4122].
[3, uuidBytes]: Major Type 4 (array) containing a
Major Type 0 (unsigned integer) item followed by a Major Type 2
(byte string) item of length 16.
[3, rest]: Major Type 4 (array) containing a
Major Type 0 (unsigned integer) item followed by a Major Type 3
(text string) item.
This algorithm takes a CBOR array valueToDecode, and returns
a decoder object or undefined.
valueToDecode has exactly two elements, and the second
element is either a byte string or a text string, return a decoder object.
undefined.
This algorithm takes a decoder object and a CBOR array
valueToDecode, and returns a string.
valueToDecode[1] is a text string, set uuid
to valueToDecode[1].
uuid to the UUID string representation of the
16-byte binary value valueToDecode[1] per [RFC4122]
(lowercase, hyphen-delimited form).
"urn:uuid:" and
uuid.
The Data URL Codec handles values whose URI scheme is
data:, as defined in [RFC2397]. Base64-encoded data URLs
(matching data:<mediatype>;base64,<data>) are
encoded as a three-element CBOR array
[4, mediatype, dataBytes]. Non-base64 data URLs are encoded
as a two-element CBOR array [4, rest] where
rest is the portion of the URL after "data:".
This algorithm takes a string value, and returns an encoder
object or undefined.
value does not start with "data:", return
undefined.
value against the pattern
data:(?<mediatype>.*);base64,(?<data>.*).
data to the value of the data capture
group.
data from base64 and
re-encode to base64. If the result equals data, return an
encoder object with value and base64 set to
true.
value and base64
set to false.
This algorithm takes an encoder object from 5.5.3.8.1 Create Data URL Encoder, and returns CBOR binary data.
schemeId to 4 (the entry for
"data:" in the URL Scheme Table).
encoderData.base64 is true:
encoderData.value to extract mediatype
(the substring between "data:" and ";base64,")
and dataBytes (the binary decoding of the base64 data
portion).
[schemeId, mediatype, dataBytes]: Major Type 4 (array)
containing a Major Type 0 integer, a Major Type 3 text string, and a
Major Type 2 byte string.
rest to the substring of encoderData.value
beginning after "data:".
[schemeId, rest]: Major Type 4 (array) containing a
Major Type 0 integer and a Major Type 3 text string.
This algorithm takes a CBOR array valueToDecode, and returns
a decoder object or undefined.
valueToDecode has exactly three elements, the second
element is a text string, and the third element is a byte string, return
a decoder object (base64 mode).
valueToDecode has exactly two elements and
the second element is a text string, return a decoder object
(non-base64 mode).
undefined.
This algorithm takes a decoder object and a CBOR array
valueToDecode, and returns a string.
valueToDecode has three elements (base64 mode):
mediatype to valueToDecode[1].
encodedData to the base64 encoding of the byte string
valueToDecode[2].
"data:",
mediatype, ";base64,", and
encodedData.
"data:" and valueToDecode[1].
The Base58 DID URL Codec handles DID URLs using the
did:v1:nym: and did:key: schemes, whose
authority (and optional fragment) components are typically multibase
base58btc-encoded strings (those starting with the character
'z'). A compressed DID URL is encoded as a two- or
three-element CBOR array [schemeId, authority] or
[schemeId, authority, fragment]. When a component starts
with 'z' and is valid base58btc, it is stored as a raw byte
string; otherwise it is stored as a text string.
This algorithm takes a string value and a string
scheme, and returns an encoder object or
undefined.
[scheme, schemeId] pair in the
URL Scheme Table where the scheme starts with
"did:":
value starts with scheme, return an encoder
object containing value, scheme, and
schemeId.
undefined.
This algorithm takes an encoder object from 5.5.3.9.1 Create Base58 DID URL Encoder, and returns CBOR binary data.
suffix to the substring of encoderData.value
beginning after encoderData.scheme.
suffix on the first occurrence of '#'
to produce authority and, if present,
fragment.
authorityEncoded to the result of applying the
Multibase Base58 to CBOR Token algorithm to
authority.
entries to
[encoderData.schemeId, authorityEncoded].
fragment is defined:
fragmentEncoded to the result of applying the
Multibase Base58 to CBOR Token algorithm to
fragment.
fragmentEncoded to entries.
entries as a Major Type 4
(array).
The Multibase Base58 to CBOR Token algorithm takes a string
str and returns either a Major Type 2 (byte string) CBOR
token (if the value is a base58btc multibase string) or a Major Type 3
(text string) CBOR token.
str starts with 'z':
decoded to the result of decoding the base58btc content
of str (i.e. str[1:]).
decoded.
str.
This algorithm takes a CBOR array valueToDecode, and returns
a decoder object or undefined.
valueToDecode has exactly two or three elements:
prefix to the value of valueToDecode[0]
in the URL Scheme Reverse Table.
prefix.
undefined.
This algorithm takes a decoder object from
5.5.3.9.4 Create Base58 DID URL Decoder and a CBOR array
valueToDecode, and returns a string.
url to decoderData.prefix.
valueToDecode[1] is a byte string, append
'z' followed by the base58btc encoding of
valueToDecode[1] to url.
valueToDecode[1] to url.
valueToDecode has more than two elements:
valueToDecode[2] is a byte string, append
"#z" followed by the base58btc encoding of
valueToDecode[2] to url.
"#" followed by
valueToDecode[2] to url.
url.
The XSD Date Codec compresses values whose type is
http://www.w3.org/2001/XMLSchema#date. A date value is
represented as an integer count of seconds since the Unix epoch
(1970-01-01T00:00:00Z), encoded as a CBOR Major Type 0 (unsigned
integer) for non-negative values or Major Type 1 (negative integer) for
dates before the epoch. The codec only compresses date strings that
exactly round-trip through this representation; otherwise the original
string is retained verbatim.
This algorithm takes a string value, and returns an encoder
object or undefined.
value contains the character 'T' (indicating
a time component), return undefined (this value is
compressed instead by the XSD DateTime
Codec).
parsed to the result of parsing value as
an ISO 8601 date string, expressed as the number of milliseconds since
the Unix epoch.
parsed is not a valid number, return
undefined.
value and
parsed.
This algorithm takes an encoder object from 5.5.4.1 Create XSD Date Encoder, and returns CBOR binary data.
secondsSinceEpoch to
floor(encoderData.parsed / 1000).
reconstituted to the ISO 8601 string for the instant
secondsSinceEpoch × 1000 milliseconds since the Unix
epoch.
expectedDate to the substring of
reconstituted preceding the first occurrence of
'T'.
encoderData.value is not equal to
expectedDate, the compression would be lossy. Return a CBOR
encoding of encoderData.value as a Major Type 3 (text
string) object.
secondsSinceEpoch is greater than or equal to
0, return a CBOR encoding of
secondsSinceEpoch as a Major Type 0 (unsigned integer)
object.
secondsSinceEpoch
as a Major Type 1 (negative integer) object.
This algorithm takes a value valueToDecode, and returns a
decoder object or undefined.
valueToDecode is an integer (positive, negative, or
zero), return a decoder object.
undefined.
This algorithm takes a decoder object and an integer value
value, and returns a string.
dateString to the ISO 8601 string for the instant
value * 1000 milliseconds since the Unix epoch.
dateString preceding the first
occurrence of 'T'.
The XSD DateTime Codec compresses values whose type is
http://www.w3.org/2001/XMLSchema#dateTime. Second-precision
datetime values are encoded as a single integer count of seconds since
the Unix epoch (Major Type 0 or 1). Sub-second-precision datetime values
are encoded as a two-element CBOR array [seconds,
milliseconds], both as Major Type 0 integers. As with the XSD
Date Codec, the value is only compressed if the compression is lossless
(the original string round-trips through the encoding exactly).
This algorithm takes a string value, and returns an encoder
object or undefined.
value does not contain the character 'T',
return undefined (this value is compressed instead by the
XSD Date Codec).
parsed to the result of parsing value as an
ISO 8601 datetime string, expressed as the number of milliseconds since
the Unix epoch.
parsed is not a valid number, return
undefined.
value and
parsed.
This algorithm takes an encoder object from 5.5.5.1 Create XSD DateTime Encoder, and returns CBOR binary data.
secondsSinceEpoch to
floor(encoderData.parsed / 1000).
encoderData.value does not contain the character
'.' (no millisecond component):
expectedDate to the ISO 8601 string for the instant
secondsSinceEpoch * 1000 milliseconds since the Unix
epoch, with the substring ".000Z" replaced by
"Z".
encoderData.value is not equal to
expectedDate, the compression would be lossy. Return a
CBOR encoding of encoderData.value as a Major Type 3
(text string) object.
secondsSinceEpoch is greater than or equal to
0, return a CBOR encoding of
secondsSinceEpoch as a Major Type 0 (unsigned integer)
object.
secondsSinceEpoch as
a Major Type 1 (negative integer) object.
millisecondIndex to the index of the first
'.' in encoderData.value.
milliseconds to the integer value of the digits of
encoderData.value beginning at position
millisecondIndex + 1.
expectedDate to the ISO 8601 string for the instant
secondsSinceEpoch * 1000 + milliseconds milliseconds
since the Unix epoch.
encoderData.value is not equal to
expectedDate, the compression would be lossy. Return a
CBOR encoding of encoderData.value as a Major Type 3
(text string) object.
[secondsSinceEpoch, milliseconds]: Major Type 4 (array)
containing two Major Type 0 (unsigned integer) items.
This algorithm takes a value valueToDecode, and returns a
decoder object or undefined.
valueToDecode is an integer, return a decoder object.
valueToDecode is an array of exactly two elements where
both elements are numbers, return a decoder object.
undefined.
This algorithm takes a decoder object and a value value
(either an integer or a two-element array of integers), and returns a
string.
value is an integer:
instantMs to value * 1000.
dateString to the ISO 8601 string for the instant
instantMs milliseconds since the Unix epoch.
dateString with the substring ".000Z"
replaced by "Z".
value is a two-element array):
instantMs to
value[0] * 1000 + value[1].
instantMs.
The Multibase Codec compresses values whose type is
https://w3id.org/security#multibase. A multibase-encoded
string is converted to a raw byte string whose first byte is the
Multibase Prefix Byte and whose remaining bytes are the decoded
binary payload. This allows the binary payload to be stored compactly
without the overhead of the base-encoding characters.
The following multibase encodings are supported:
| Multibase Prefix Character | Multibase Prefix Byte | Encoding |
|---|---|---|
z |
0x7a |
Base58btc |
u |
0x75 |
Base64url (no padding) |
M |
0x4d |
Base64pad |
This algorithm takes a value value, and returns an encoder
object or undefined.
value is not a string, return undefined.
value is 'z',
'u', or 'M', return an encoder object
containing value.
undefined (unsupported multibase
encoding).
This algorithm takes an encoder object from 5.5.6.1 Create Multibase Encoder, and returns CBOR binary data.
prefixChar to the first character of
encoderData.value.
prefixByte to the Multibase Prefix Byte
corresponding to prefixChar.
content to the substring of
encoderData.value beginning after the first character.
prefixChar is 'z', set
suffixBytes to the base58btc decoding of
content.
prefixChar is 'u', set
suffixBytes to the base64url decoding of
content.
prefixChar is 'M'), set
suffixBytes to the base64pad decoding of
content.
bytes to a byte array of length
1 + length(suffixBytes), with the first byte set to
prefixByte and the remaining bytes set to
suffixBytes.
bytes as a Major Type 2 (byte
string) object.
This algorithm takes a value valueToDecode, and returns a
decoder object or undefined.
valueToDecode is not a byte string, return
undefined.
valueToDecode is 0x7a,
0x75, or 0x4d, return a decoder object.
undefined (unsupported multibase
prefix byte).
This algorithm takes a decoder object and a byte string
value, and returns a string.
prefixByte to the first byte of value.
suffix to the remaining bytes of value
(i.e., all bytes after the first).
prefixByte is 0x7a ('z'):
"z" and the base58btc encoding
of suffix.
prefixByte is 0x75 ('u'):
"u" and the base64url encoding
(no padding) of suffix.
prefixByte is 0x4d ('M'):
"M" and the base64pad encoding
of suffix.
value.
registryEntryId, and returns a byte string prefix.
registryEntryBytes to the CBOR encoding of registryEntryID
prefix to the result of appending registryEntryBytes to the end
of the bytestring 0xD9CB1D82.
prefix.
This algorithm takes an encoded CBOR-LD payload cborldBytes as input, and returns
suffix, the main data to be decoded, as well as the registryEntryId value that
should be used to decompress suffix.
cborldbytes is not 0xCB1D (tag value 51997),
throw an ERR_NON_CBOR_LD_TAG error.
ERR_INVALID_PAYLOAD_STRUCTURE error.
registryEntryId to the value of the integer at index 0 of the tagged
array.
suffix to the value of the second element of the array.
result to be an empty map.
result.suffix to the value of suffix and result.registryEntryId to
the value of registryEntryId.
result.
This section is non-normative.
This section is non-normative.
This section is non-normative.
This specification registers a CBOR tag to allow consumers to identify CBOR-LD payloads. The following is provisional, and has not yet been ratified by IANA.
Tag: 51997
Registry: https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml
Data item: array
Semantics: a tag value of 51997 indicates that the payload is CBOR-LD.
Description of semantics: https://w3c.github.io/cbor-ld/#cbor-tags-for-cbor-ld
Point of contact: Wesley Smith (wsmith@digitalbazaar.com)
Referenced in:
Referenced in: