This document is also available in this non-normative format: diff to previous version
Copyright
©
2010-2012
W3C
®
(
MIT
,
ERCIM
,
Keio
2010-2013
the
Contributors
to
the
JSON-LD
1.0
Processing
Algorithms
and
API
Specification,
published
by
the
RDF
Working
Group
),
All
Rights
Reserved.
under
the
W3C
liability
,
trademark
and
document
use
Community
Final
Specification
Agreement
(FSA)
.
A
human-readable
summary
rules
apply.
is
available.
JSON
[
RFC4627
]
has
proven
to
be
a
highly
useful
object
serialization
and
messaging
format.
JSON-LD
[
JSON-LD
]
harmonizes
the
representation
of
Linked
Data
in
JSON
by
outlining
a
common
JSON
representation
format
for
expressing
directed
graphs;
mixing
both
Linked
Data
and
non-Linked
Data
in
a
single
document.
This
document
outlines
specification
defines
an
Application
Programming
Interface
(API)
and
a
set
of
algorithms
for
programmatically
transforming
programmatic
transformations
of
JSON-LD
documents
documents.
By
expressing
the
data
in
order
to
make
them
easier
a
way
that
is
specifically
tailored
to
work
with
in
programming
environments
like
JavaScript,
Python,
and
Ruby.
a
particular
use
case,
the
processing
typically
becomes
much
simpler.
This
section
describes
the
status
of
this
document
at
specification
was
published
by
the
time
of
its
publication.
Other
documents
may
supersede
this
document.
A
list
of
current
RDF
Working
Group
.
It
is
not
a
W3C
publications
and
Standard
nor
is
it
on
the
latest
revision
of
this
technical
report
can
be
found
in
W3C
Standards
Track.
Please
note
that
under
the
W3C
technical
reports
index
Community
Final
Specification
Agreement
(FSA)
at
http://www.w3.org/TR/.
other
conditions
apply.
Learn
more
about
W3C
Community
and
Business
Groups
.
This
document
has
been
under
development
for
over
18
25
months
in
the
JSON
for
Linking
Data
Community
Group.
The
document
has
recently
been
transferred
to
the
RDF
Working
Group
for
review,
improvement,
and
publication
along
the
Recommendation
track.
The
specification
has
undergone
significant
development,
review,
and
changes
during
the
course
of
the
last
18
25
months.
There
are
several
independent
interoperable
implementations
of
this
specification.
There
is
a
fairly
complete
test
suite
and
a
live
JSON-LD
editor
that
is
capable
of
demonstrating
the
features
described
in
this
document.
While
there
will
be
continuous
development
on
implementations,
the
test
suite
suite,
and
the
live
editor
will
continue,
editor,
they
are
believed
to
be
mature
enough
to
be
integrated
into
a
non-production
system
at
this
point
in
time
with
the
time.
There
is
an
expectation
that
they
could
be
used
in
a
production
system
within
the
next
year.
six
months.
It is important for readers to understand that the scope of this document is currently under debate and new features may be added to the specification. Existing features may be modified heavily or removed entirely from the specification upon further review and feedback from the broader community. This is a work in progress and publication as a Working Draft does not require that all Working Group members agree on the content of the document.
There are a number of ways that one may participate in the development of this specification:
This section is non-normative.
This
document
is
a
detailed
specification
for
an
Application
Programming
Interface
for
the
JSON-LD
Syntax.
syntax.
The
document
is
primarily
intended
for
the
following
audiences:
To
understand
the
basics
in
this
specification
you
must
first
be
familiar
with
JSON,
which
is
detailed
in
[
RFC4627
].
You
must
also
understand
the
JSON-LD
Syntax
[
JSON-LD
],
which
is
the
base
syntax
used
by
all
of
the
algorithms
in
this
document.
To
understand
the
API
and
how
it
is
intended
to
operate
in
a
programming
environment,
it
is
useful
to
have
working
knowledge
of
the
JavaScript
programming
language
[
ECMA-262
]
and
WebIDL
[
WEBIDL
].
To
understand
how
JSON-LD
maps
to
RDF,
it
is
helpful
to
be
familiar
with
the
basic
RDF
concepts
[
RDF-CONCEPTS
RDF11-CONCEPTS
].
This section is non-normative.
The
JSON-LD
Syntax
specification
[
JSON-LD
]
outlines
a
language
syntax
that
may
be
used
to
express
Linked
Data
in
JSON.
Often,
Because
there
is
more
than
one
way
to
express
Linked
Data
using
this
syntax,
it
is
often
useful
to
be
able
to
transform
JSON-LD
documents
so
that
they
may
be
more
easily
processed
consumed
by
specific
applications.
The
way
JSON-LD
allows
Linked
Data
to
be
expressed
in
various
programming
environments.
a
way
that
is
specifically
tailored
to
a
particular
person
or
application
is
by
providing
a
context
.
By
providing
a
context
,
JSON
data
can
be
expressed
in
a
way
that
is
a
natural
fit
for
a
particular
person
or
application
whilst
also
indicating
how
the
data
should
be
understood
at
a
global
scale.
In
order
for
people
or
applications
to
share
data
that
was
created
using
a
context
that
is
different
from
their
own,
a
JSON-LD
processor
must
be
able
to
transform
a
document
from
one
context
to
another.
Instead
of
requiring
JSON-LD
processors
to
write
specific
code
for
every
imaginable
context
switching
scenario,
it
is
much
easier
to
specify
a
single
algorithm
that
can
remove
any
context
.
Similarly,
another
algorithm
can
be
specified
to
subsequently
apply
any
context
.
These
two
algorithms
represent
the
most
basic
transformations
of
JSON-LD
documents.
They
are
referred
to
as
expansion
and
compaction
,
respectively.
There are four major types of transformation that are discussed in this document: expansion, compaction, flattening, and RDF conversion.
This section is non-normative.
Software
algorithms
are
easiest
to
write
when
the
data
The
algorithm
that
they
are
processing
have
removes
context
is
called
expansion
.
Before
performing
any
other
transformations
on
a
regular
form.
Since
information
can
be
represented
by
JSON-LD
in
a
variety
of
different
ways,
transforming
document,
it
is
easiest
to
remove
any
context
from
it,
localizing
all
information,
and
to
make
data
structures
more
regular.
To
get
an
idea
of
these
methods
into
a
uniform
structure
allows
how
context
and
data
structuring
affects
the
developer
to
simplify
their
processing
code.
For
example,
note
same
data,
here
is
an
example
of
JSON-LD
that
the
following
input
uses
only
term
terms
s
and
is
fairly
compact:
{ "@context": { "name": "http://xmlns.com/foaf/0.1/name", "homepage": { "@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "@id" } }, "@id": "http://me.markus-lanthaler.com/", "name": "Markus Lanthaler", "homepage": "http://www.markus-lanthaler.com/" }
The
next
input
example
uses
one
IRI
to
express
a
property,
property
and
array
to
encapsulate
another,
but
leaves
the
rest
of
the
information
untouched.
{ "@context": { "website": "http://xmlns.com/foaf/0.1/homepage" }, "@id": "http://me.markus-lanthaler.com/", "http://xmlns.com/foaf/0.1/name": "Markus Lanthaler", "website": { "@id": "http://www.markus-lanthaler.com/" } }
While
Note
that
both
inputs
are
valid
JSON-LD,
writing
a
program
to
handle
every
permutation
of
possible
inputs
can
be
difficult,
especially
when
JSON-LD
and
both
represent
the
incoming
same
information.
The
difference
is
in
their
context
could
change
as
well.
To
information
and
in
the
data
structures
used.
A
JSON-LD
processor
can
remove
context
and
ensure
that
the
data
can
be
given
a
is
more
uniform
structure,
JSON-LD
introduces
the
notion
of
expansion.
regular
by
employing
expansion
.
Expansion
performs
has
two
important
operations.
The
first
is
to
expand
goals:
removing
any
contextual
information
from
the
document,
and
ensuring
all
values
that
represent
IRIs
are
represented
in
a
regular
form.
These
goals
are
accomplished
by
expanding
all
properties
to
absolute
IRIs
.
The
second
is
to
express
and
by
expressing
all
values
in
arrays
in
expanded
form
.
Expanded
form
is
the
most
verbose
and
regular
way
of
expressing
of
values
in
JSON-LD;
all
contextual
information
from
the
document
is
instead
stored
locally
with
each
value.
Running
the
Expansion
algorithm
(
expand
operation)
against
the
examples
provided
above
results
in
the
following
output:
[ { "@id": "http://me.markus-lanthaler.com/", "http://xmlns.com/foaf/0.1/name": [ { "@value": "Markus Lanthaler" } ], "http://xmlns.com/foaf/0.1/homepage": [ { "@id": "http://www.markus-lanthaler.com/" } ] } ]
Note
that
in
the
output
above
all
context
definitions
have
been
removed,
all
terms
and
prefixes
compact
IRIs
have
been
expanded
to
absolute
IRIs
,
and
all
JSON-LD
values
are
expressed
in
arrays
in
expanded
form
.
While
the
output
is
more
verbose
and
difficult
for
a
human
to
read,
it
is
easier
for
establishes
a
software
program
to
process
baseline
that
makes
JSON-LD
processing
easier
because
of
its
very
regular
structure.
This section is non-normative.
While
expansion
expands
removes
context
from
a
given
input
as
much
as
possible,
compaction
performs
input,
compaction's
primary
function
is
to
perform
the
opposite
operation:
it
expresses
to
express
a
given
input
as
succinctly
as
possible.
In
contrast
to
expansion
which
is
meant
according
to
produce
something
a
particular
context
.
Compaction
applies
a
context
that
specifically
tailors
the
way
information
is
easy
to
process
by
software
programs,
compaction
is
meant
to
produce
something
expressed
for
a
particular
person
or
application.
This
simplifies
applications
that
is
easy
consume
JSON
or
JSON-LD
by
expressing
the
data
in
application-specific
terms,
and
it
makes
the
data
easier
to
read
by
software
developers.
humans.
Compaction
uses
a
developer-supplied
context
to
compress
shorten
IRIs
to
terms
or
compact
IRIs
and
JSON-LD
values
expressed
in
expanded
form
to
simple
values
such
as
strings
and
or
numbers
.
For example, assume the following expanded JSON-LD input document:
[ { "@id": "http://me.markus-lanthaler.com/", "http://xmlns.com/foaf/0.1/name": [ { "@value": "Markus Lanthaler" } ], "http://xmlns.com/foaf/0.1/homepage": [ { "@id": "http://www.markus-lanthaler.com/" } ] } ]
Additionally, assume the following developer-supplied JSON-LD context :
{ "@context": { "name": "http://xmlns.com/foaf/0.1/name", "homepage": { "@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "@id" } } }
Running
the
Compaction
Algorithm
(
compact
operation)
given
the
context
supplied
above
against
the
JSON-LD
input
document
provided
above
would
result
in
the
following
output:
{ "@context": { "name": "http://xmlns.com/foaf/0.1/name", "homepage": { "@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "@id" } }, "@id": "http://me.markus-lanthaler.com/", "name": "Markus Lanthaler", "homepage": "http://www.markus-lanthaler.com/" }
Note
that
all
IRIs
have
been
compacted
to
terms
as
specified
in
the
context
,
which
consequently
has
been
injected
into
the
output.
While
compacted
output
is
most
useful
to
humans,
it
can
often
is
also
be
used
to
generate
structures
that
are
easy
to
program
against.
Compaction
enables
developers
to
map
any
expanded
document
into
an
application-specific
compacted
document.
While
the
context
provided
above
mapped
to
http://xmlns.com/foaf/0.1/name
http://xmlns.com/foaf/0.1/nam
name
,
it
could
have
also
have
been
mapped
to
any
other
term
provided
by
the
developer.
This section is non-normative.
While
expansion
ensures
that
a
document
is
in
a
uniform
structure,
flattening
goes
a
step
further
and
ensures
to
ensure
that
also
the
shape
of
the
data
is
deterministic.
In
expanded
documents
documents,
the
properties
of
a
single
node
may
still
be
spread
across
a
number
of
different
JSON
objects
.
By
flattening
a
document,
all
properties
of
a
node
are
collected
in
a
single
JSON
object
and
all
blank
nodes
are
labeled
with
a
blank
node
identifier
.
Often
this
This
may
drastically
simplifies
simplify
the
code
required
to
process
JSON-LD
data.
data
in
certain
applications.
For example, assume the following JSON-LD input document:
{ "@context": { "name": "http://xmlns.com/foaf/0.1/name", "knows": "http://xmlns.com/foaf/0.1/knows" }, "@id": "http://me.markus-lanthaler.com/", "name": "Markus Lanthaler", "knows": [ { "name": "Dave Longley" } ] }
Running
the
Flattening
Algorithm
algorithm
(
flatten
operation)
with
a
context
set
to
null
to
prevent
compaction
returns
the
following
document:
[ { "@id": "_:t0", "http://xmlns.com/foaf/0.1/name": [ { "@value": "Dave Longley" } ] }, { "@id": "http://me.markus-lanthaler.com/", "http://xmlns.com/foaf/0.1/name": [ { "@value": "Markus Lanthaler" } ], "http://xmlns.com/foaf/0.1/knows": [ { "@id": "_:t0" } ] } ]
Note
how
in
the
output
above
all
properties
of
a
node
are
collected
in
a
single
JSON
object
and
how
the
blank
node
representing
"Manu
Sporny"
"Dave
Longley"
has
been
assigned
the
blank
node
identifier
_:t0
.
To
make
it
easier
for
humans
to
read
such
or
for
certain
applications
to
process
it,
a
flattened
document
can
be
compacted
by
passing
a
context.
Using
the
same
context
as
the
input
document,
the
flattened
and
compacted
document
looks
as
follows:
{ "@context": { "name": "http://xmlns.com/foaf/0.1/name", "knows": "http://xmlns.com/foaf/0.1/knows" }, "@graph": [ { "@id": "_:t0", "name": "Dave Longley" }, { "@id": "http://me.markus-lanthaler.com/", "name": "Markus Lanthaler", "knows": { "@id": "_:t0" } } ] }
Please
note
that
the
flattened
and
compacted
result
will
always
explicitly
designate
designates
the
default
graph
by
the
@graph
member
in
the
top-level
JSON
object
.
Compaction
optimizes
that
member
away
if
its
value
contains
just
one
item.
This section is non-normative.
JSON-LD
can
be
used
to
serialize
data
expressed
in
RDF
as
described
in
[
RDF-CONCEPTS
RDF11-CONCEPTS
].
This
ensures
that
data
can
be
round-tripped
from
and
to
and
from
any
RDF
syntax
without
any
loss
in
the
fidelity
of
the
data.
fidelity.
For
example,
assume
the
following
RDF
input
serialized
in
Turtle
[
TURTLE-TR
TURTLE
]:
<http://me.markus-lanthaler.com/> <http://xmlns.com/foaf/0.1/name> "Markus Lanthaler" . <http://me.markus-lanthaler.com/> <http://xmlns.com/foaf/0.1/homepage> <http://www.markus-lanthaler.com/> .
Using
the
Convert
from
RDF
Algorithm
algorithm
a
developer
could
transform
this
document
into
expanded
JSON-LD:
[ { "@id": "http://me.markus-lanthaler.com/", "http://xmlns.com/foaf/0.1/name": [ { "@value": "Markus Lanthaler" } ], "http://xmlns.com/foaf/0.1/homepage": [ { "@id": "http://www.markus-lanthaler.com/" } ] } ]
Note
that
the
output
above
could
easily
be
compacted
using
the
technique
outlined
in
the
previous
section.
It
is
also
possible
to
transform
the
JSON-LD
document
back
to
RDF
using
the
Convert
to
RDF
Algorithm
algorithm
.
All examples and notes as well as sections marked as non-normative in this specification are non-normative. Everything else in this specification is normative.
The
keywords
must
MUST
,
must
not
MUST
NOT
,
required
REQUIRED
,
should
SHOULD
,
should
not
SHOULD
NOT
,
recommended
RECOMMENDED
,
may
MAY
,
and
optional
OPTIONAL
in
this
specification
are
to
be
interpreted
as
described
in
[
RFC2119
].
There are two classes of products that can claim conformance to this specification: JSON-LD Implementations and JSON-LD Processors .
A conforming JSON-LD Implementation is a system capable of transforming JSON-LD documents according the algorithms defined in this specification.
A
conforming
JSON-LD
Processor
is
a
conforming
JSON-LD
Implementation
that
exposes
the
application
programming
interface
Application
Programming
Interface
(API)
defined
in
this
specification.
It
MUST
implement
the
json-ld-1.0
processing
mode
(for
further
details,
see
the
processingMode
option
of
JsonLdOptions
).
The
algorithms
in
this
specification
are
generally
written
with
more
concern
for
clarity
than
over
efficiency.
Thus,
JSON-LD
Implementations
and
Processors
may
implement
the
algorithms
given
in
this
specification
in
any
way
desired,
so
long
as
the
end
result
is
indistinguishable
from
the
result
that
would
be
obtained
by
the
specification's
algorithms.
This
specification
does
not
define
how
JSON-LD
Implementations
or
Processors
handle
non-conforming
input
documents.
This
implies
that
JSON-LD
Implementations
or
Processors
must
not
MUST
NOT
attempt
to
correct
malformed
IRIs
or
language
tags;
however,
they
may
MAY
issue
validation
warnings.
IRIs
are
not
modified
other
than
converted
between
relative
and
absolute
IRIs
.
Implementers can partially check their level of conformance to this specification by successfully passing the test cases of the JSON-LD test suite [ JSON-LD-TESTS ]. Note, however, that passing all the tests in the test suite does not imply complete conformance to this specification. It only implies that the implementation conforms to aspects tested by the test suite.
This document uses the following terms as defined in JSON [ RFC4627 ]. Refer to the JSON Grammar section in [ RFC4627 ] for formal definitions.
@context
where
the
value,
or
the
@id
of
the
value,
is
null
explicitly
decouples
a
term's
association
with
an
IRI
.
A
key-value
pair
in
the
body
of
a
JSON-LD
document
whose
value
is
null
has
the
same
meaning
as
if
the
key-value
pair
was
not
defined.
If
@value
,
@list
,
or
@set
is
set
to
null
in
expanded
form,
then
the
entire
JSON
object
is
ignored.
Furthermore, the following terminology is used throughout this document:
_:
.
@context
keyword
.
@value
,
@list
,
or
@set
keywords,
or
@graph
@context
.
@value
member.
@list
member.
@set
member.
The
algorithm
takes
three
input
variables:
an
When
processing
a
JSON-LD
data
structure,
each
processing
rule
is
applied
using
information
provided
by
the
active
context
,
.
This
section
describes
how
to
produce
an
active
property
,
and
an
element
to
be
expanded.
To
begin,
the
context
.
The
active
context
is
set
to
contains
the
result
of
performing,
Context
Processing
on
active
term
definitions
which
specify
how
properties
and
values
have
to
be
interpreted
as
well
as
the
passed
current
base
IRI
expandContext
,
the
vocabulary
mapping
and
the
default
language
.
Each
term
definition
consists
of
an
,
IRI
mapping
,
a
boolean
flag
reverse
property
,
an
optional
type
mapping
or
empty
if
expandContext
language
mapping
,
and
an
optional
container
mapping
.
A
term
definition
can
not
only
be
used
to
map
a
term
to
an
IRI
,
but
also
to
map
a
term
to
a
keyword
,
in
which
case
it
is
null
referred
to
as
a
keyword
alias
.
When
processing,
the
active
context
is
initialized
without
any
term
definitions
,
vocabulary
mapping
,
or
default
language
.
If
a
local
context
is
encountered
during
processing,
a
new
active
property
context
is
set
created
by
cloning
the
existing
active
context
.
Then
the
information
from
the
local
context
is
merged
into
the
new
active
context
.
Given
that
local
contexts
may
contain
references
to
null
,
and
remote
contexts,
this
includes
their
retrieval.
element
This
section
is
set
to
non-normative.
First
we
prepare
a
new
active
context
result
by
cloning
the
JSON-LD
input
current
active
context
.
This
algorithm
expects
Then
we
normalize
the
JSON-LD
input
form
the
passed
local
context
to
an
array
.
Local
contexts
may
be
in
the
form
of
a
well-formed
JSON-LD
document
as
defined
JSON
object
,
a
string
,
or
an
array
containing
a
combination
of
the
two.
Finally
we
process
each
context
contained
in
[
JSON-LD
the
local
context
].
array
as
follows.
If
element
context
is
a
scalar
string
,
expand
it
according
represents
a
reference
to
a
remote
context.
We
dereference
the
Value
Expansion
remote
context
and
replace
context
algorithm,
passing
copies
with
the
value
of
the
active
@context
key
of
the
top-level
object
in
the
retrieved
JSON-LD
document.
If
there's
no
such
key,
an
invalid
remote
context
has
been
detected.
Otherwise,
we
process
context
by
recursively
using
this
algorithm
ensuring
that
there
is
no
cyclical
reference.
If
context
is
a
JSON
object
,
we
first
update
the
base
IRI
,
the
vocabulary
mapping
,
and
active
property
the
default
language
by
processing
three
specific
keywords:
@base
,
@vocab
,
and
return.
If
element
is
null
@language
.
These
are
handled
before
any
other
keys
in
the
local
context
because
they
affect
how
the
other
keys
are
processed.
Then,
for
every
other
key
in
local
context
,
return.
If
element
we
update
the
term
definition
in
result
.
Since
term
definitions
in
a
local
context
may
themselves
contain
terms
or
compact
IRIs
,
we
may
need
to
recurse.
When
doing
so,
we
must
ensure
that
there
is
no
cyclical
dependency,
which
is
an
array
error.
After
we
have
processed
any
term
definition
dependencies,
we
update
the
current
term
definition
,
initialize
an
empty
array
which
may
be
a
keyword
alias
.
Finally,
we
return
result
.
Expand
each
item
by
recursively
using
this
algorithm,
passing
copies
of
as
the
new
active
context
and
active
property
.
If
the
This
algorithm
specifies
how
a
new
active
property's
container
mapping
context
is
set
to
@list
updated
with
a
local
context
.
The
algorithm
takes
three
input
variables:
an
active
context
,
a
local
context
,
and
the
expanded
item
is
an
array
or
a
list
object
trigger
a
LIST_OF_LISTS_DETECTED
error.
remote
contexts
which
is
used
to
detect
cyclical
context
inclusions.
If
the
expanded
item
remote
contexts
is
null
,
drop
it.
Otherwise,
if
the
expanded
item
not
passed,
it
is
initialized
to
an
empty
array
,
merge
its
entries
with
result's
entries.
.
INVALID_VALUE_OBJECT_VALUE
recursive
context
inclusion
@set
@context
invalid
remote
context
has
been
detected
and
processing
is
aborted;
otherwise,
set
context
to
the
,i.e.,
it
doesn't
contain
a
colon,
continue
with
the
next
member
from
element
.
Otherwise,
if
property's
container
mapping
invalid
local
context
is
set
to
@language
@value
@base
This
feature
is
at
risk
as
the
currently
processed
item
and
fact
that
a
document
may
have
multiple
base
IRIs
is
potentially
confusing
for
developers.
It
is
also
being
discussed
whether
relative
IRIs
are
allowed
as
values
of
@language
@base
set
to
or
whether
the
lowercased
key
.
If
val
is
not
a
empty
string
,
trigger
a
LANGUAGE_MAP_INVALID_VALUE
error.
Otherwise
append
the
object
to
language
map
values
.
Set
value
should
be
used
to
language
map
values
.
Otherwise,
if
property's
container
mapping
is
set
explicitly
specify
that
there
isn't
a
base
IRI
,
which
could
be
used
to
@annotation
ensure
that
relative
IRIs
remain
relative
when
expanding.
@annotation
@base
invalid
base
IRI
with
an
@list
@vocab
key:
@vocab
key.
invalid
vocab
mapping
@type
@language
@type
member
is
a
string.
If
not,
trigger
an
INVALID_TYPED_VALUE
@language
invalid
default
language
@base
,
@vocab
,
or
@language
member,
set
element
to
null.
,
invoke
the
Create
Term
Definition
algorithm
,
passing
result
for
active
context
,
context
for
local
context
,
key
,
and
defined
.
If,
after
the
This
algorithm
outlined
above
is
run,
called
from
the
resulting
element
is
an
JSON
object
Context
Processing
algorithm
with
just
a
@graph
member,
element
is
set
to
create
a
term
definition
in
the
value
of
@graph
's
value.
Finally,
if
element
is
active
context
for
a
JSON
object
,
it
is
wrapped
into
an
array
term
being
processed
in
a
local
context
.
Processing
of
JSON-LD
data
structure
is
managed
recursively.
During
processing,
each
rule
This
section
is
applied
using
information
provided
by
the
active
context
.
non-normative.
The
active
Term
definitions
are
created
by
parsing
the
information
in
the
given
local
context
contains
for
the
active
given
term
definitions
which
specify
how
properties
and
values
have
to
be
interpreted
as
well
as
the
current
vocabulary
mapping
and
.
If
the
default
language
.
Each
given
term
definition
consists
of
an
is
a
compact
IRI
mapping
and
optionally
a
type
mapping
from
terms
to
datatypes
or
language
mapping
from
terms
to
language
codes,
and
a
container
mapping
.
If
,
it
may
omit
an
IRI
mapping
maps
a
by
depending
on
its
prefix
having
its
own
term
to
multiple
IRIs
it
is
said
to
be
a
property
generator
.
definition
.
If
a
local
context
is
encountered,
information
from
the
local
context
prefix
is
merged
into
a
key
in
the
active
context
.
A
local
context
,
then
its
term
definition
is
identified
within
must
first
be
created,
through
recursion,
before
continuing.
Because
a
JSON
object
term
definition
having
can
depend
on
other
term
definitions
,
a
@context
member
with
mechanism
must
be
used
to
detect
cyclical
dependencies.
The
solution
employed
here
uses
a
string
,
array
map,
defined
,
that
keeps
track
of
whether
or
not
a
JSON
object
term
value.
has
been
defined
or
is
currently
in
the
process
of
being
defined.
This
map
is
checked
before
any
recursion
is
attempted.
This
algorithm
specifies
how
After
all
dependencies
for
a
term
have
been
defined,
the
active
rest
of
the
information
in
the
local
context
for
the
given
term
is
updated
with
a
local
context
taken
into
account,
creating
the
appropriate
IRI
mapping
,
container
mapping
,
and
type
mapping
or
language
mapping
for
the
term
.
The
algorithm
takes
three
input
variables:
has
four
required
inputs
which
are:
an
active
context
,
a
local
context
,
a
term
,
and
an
array
of
already
included
remote
contexts
remoteContexts
.
To
begin,
remoteContexts
is
initialized
to
an
empty
array.
a
map
defined
.
cyclic
IRI
Expansion
algorithm
mapping
pass
error
has
been
detected
and
processing
is
aborted.
keyword
redefinition
error
has
been
detected
and
processing
is
aborted.
@id
-
null
,
@context
,
an
RECURSIVE_CONTEXT_INCLUSION
invalid
keyword
alias
invalid
term
definition
that
has
a
@context
@context
member
as
local
context
,
and
a
copy
of
the
remoteContexts
array.
Relative
IRIs
are
expanded
using
the
remote
context's
IRI
.
Otherwise
raise
@reverse
:
@id
,
an
@type
,
or
an
@language
,
member,
an
INVALID_REMOTE_CONTEXT
invalid
reverse
property
@reverse
key
is
not
a
INVALID_LOCAL_CONTEXT
invalid
IRI
mapping
@vocab
@reverse
:
),
INVALID_VOCAB_MAPPING
invalid
IRI
mapping
@vocab
member
from
context
.
@id
.
@container
@language
@index
@container
member;
otherwise
an
invalid
reverse
property
error
has
been
detected
(reverse
properties
only
support
index-containers)
and
processing
is
aborted.
@id
:
@id
key
is
not
a
string
,
invalid
IRI
Expansion
algorithm
mapping
error
has
been
detected
and
@id
key
:
invalid
IRI
mapping
of
definition
to
the
result
of
expanding
key
according
the
IRI
Expansion
algorithm
.
error
been
detected
and
processing
is
aborted.
@type
member
with
a
:
@type
key,
which
must
be
a
string
invalid
type
mapping
error
has
been
detected
and
processing
is
aborted.
@id
,
nor
@vocab
,
nor
an
absolute
IRI
,
an
invalid
type
mapping
of
definition
to
the
expanded
val
.
Otherwise,
if
value
has
an
@language
@container
member
with
a
:
@container
key,
which
must
be
either
@list
,
@set
,
@annotation
@index
,
@language
.
Otherwise,
an
invalid
container
mapping
error
has
been
detected
and
processing
is
aborted.
@language
and
does
not
@type
:
@language
key,
which
must
be
either
null
or
a
string
.
Otherwise,
an
INVALID_CONTAINER_MAPPING
invalid
language
mapping
In
JSON-LD
documents
documents,
some
keys
and
some
values
are
evaluated
to
produce
an
IRI
may
represent
IRIs
.
This
section
defines
an
algorithm
for
transforming
strings
representing
a
string
that
represents
an
IRI
into
an
absolute
IRI
or
blank
node
identifier
.
It
also
covers
transforming
keyword
aliases
into
keywords
.
IRI
expansion
may
occur
during
context
processing
or
during
any
of
the
other
JSON-LD
algorithms.
If
IRI
expansion
occurs
during
context
processing,
then
the
local
context
that
is
being
processed
is
and
its
related
defined
map
from
the
Context
Processing
algorithm
are
passed
to
this
algorithm.
After
application
of
this
algorithm,
values
This
allows
for
term
definition
dependencies
to
be
processed
by
this
via
the
Create
Term
Definition
algorithm
are
said
.
This section is non-normative.
In
order
to
be
in
expanded
expand
value
to
an
absolute
IRI
,
we
must
first
determine
if
it
is
null
,
a
term
,
a
keyword
alias
,
or
some
form
,
although
this
of
IRI
.
Based
on
what
we
find,
we
handle
the
specific
kind
of
expansion;
for
example,
we
expand
a
keyword
alias
to
a
keyword
and
a
term
to
an
absolute
IRI
according
to
its
IRI
mapping
in
the
active
context
.
While
inspecting
value
we
may
also
include
blank
node
identifiers
find
that
we
need
to
create
term
definition
dependencies
because
we're
running
this
algorithm
during
context
processing.
We
can
tell
whether
or
not
we're
running
during
context
processing
by
checking
local
context
against
null
.
We
know
we
need
to
create
a
term
definition
in
the
active
context
when
value
is
a
key
in
the
local
context
and
JSON-LD
keywords
the
defined
map
does
not
have
a
key
for
value
with
an
associated
value
of
true
.
The
defined
map
is
used
during
Context
Processing
to
keep
track
of
which
terms
have
already
been
defined
or
are
in
the
process
of
being
defined.
We
create
a
term
definition
by
using
the
Create
Term
Definition
algorithm
.
The
algorithm
takes
two
mandatory
required
and
four
optional
input
variables:
variables.
The
required
inputs
are
an
active
context
and
a
value
to
be
expanded,
an
active
context
,
expanded.
The
optional
inputs
are
two
flags
documentRelative
flags,
document
relative
and
vocabRelative
vocab
,
that
specifying
whether
value
should
can
be
interpreted
as
a
relative
IRI
against
the
document's
base
IRI
or
the
active
context's
vocabulary
mapping
,
along
with
an
respectively,
and
a
local
context
passed
and
a
map
defined
to
be
used
when
this
algorithm
is
used
in
during
Context
Processing
,
and
finally
an
array
path
which
is
used
to
detect
cyclic
IRI
mappings
.
If
not
passed,
the
two
flags
are
set
to
false
and
path
is
local
context
and
defined
are
initialized
to
an
empty
array
by
default.
The
algorithm
for
generating
an
IRI
is:
null
.
:
),
:
).
_
)
and
suffix
//
invalid
IRI
mapping
error
has
been
detected
and
processing
is
aborted.
If
the
result
of
the
This
algorithm
above
is
a
blank
node
identifier
,
i.e.,
expands
a
string
JSON-LD
document,
such
that
begins
with
_:
,
and
no
local
all
context
has
been
passed,
generated
a
new
definitions
are
removed,
all
terms
and
compact
IRIs
are
expanded
to
absolute
IRIs
,
blank
node
identifier
identifiers
,
or
keywords
before
returning
the
final
result.
and
all
JSON-LD
values
are
expressed
in
arrays
in
expanded
form
.
Some
values
in
This
section
is
non-normative.
Starting
with
its
root
element
,
we
can
process
the
JSON-LD
document
recursively,
until
we
have
a
fully
expanded
result
.
When
expanding
an
element
,
we
can
be
expressed
treat
each
one
differently
according
to
its
type,
in
order
to
break
down
the
problem:
Finally, after ensuring result is in an array , we return result .
The
algorithm
for
expanding
a
value
takes
three
input
variables:
an
active
context
,
an
active
property
,
and
an
element
to
be
expanded.
To
begin,
the
active
context
.
It
is
implemented
as
follows:
set
to
the
result
of
performing,
Context
Processing
on
the
passed
expandContext
,
or
empty
if
expandContext
is
null
,
active
property
is
set
to
null
,
and
element
is
set
to
the
JSON-LD
input
.
@graph
,
drop
the
free-floating
scalar
by
returning
null
.
@graph
@list
or
@id
@list
,
list
of
lists
error
has
been
detected
and
processing
is
aborted.
@id
@context
,
set
active
context
to
the
result
of
the
Context
Processing
algorithm
,
passing
active
context
and
the
value
@context
key
as
local
context
.
@context
,
continue
to
the
next
key
.:
)
nor
it
is
a
keyword
,
drop
key
by
continuing
to
@value
@reverse
,
an
invalid
reverse
property
map
error
has
been
detected
and
colliding
keywords
error
has
been
detected
and
processing
is
aborted.
@id
and
value
is
not
a
invalid
@id
value
error
has
been
detected
and
processing
is
aborted.
Otherwise,
set
expanded
value
to
the
result
@type
and
invalid
type
value
error
has
been
detected
and
processing
is
aborted.
Otherwise,
set
expanded
value
to
the
result
of
using
the
IRI
Expansion
algorithm
,
passing
active
context
,
true
@graph
,
set
expanded
value
to
the
result
of
using
this
algorithm
recursively
passing
active
context
,
@graph
for
active
property
,
and
value
for
element
.
@value
and
value
is
not
a
invalid
value
object
value
error
has
been
detected
and
processing
is
aborted.
Otherwise,
set
expanded
value
to
@value
member
of
result
to
null
and
continue
with
the
next
key
from
element
.
Null
values
need
to
be
preserved
in
this
case
as
the
meaning
of
an
@type
member
depends
on
the
existence
of
an
@value
member.
@language
and
value
is
not
a
string
,
an
invalid
language-tagged
string
error
has
been
detected
and
@index
and
value
is
not
a
invalid
@index
value
error
has
been
detected
and
processing
is
aborted.
Otherwise,
set
@list
:
@graph
,
continue
with
the
next
key
from
element
to
remove
the
free-floating
list..
list
of
lists
error
has
been
detected
and
processing
is
aborted.
@set
,
set
expanded
value
to
@language
@reverse
and
invalid
@reverse
value
or
error
has
been
detected
and
processing
is
aborted.
Otherwise
@reverse
as
active
property
@reverse
member,
i.e.,
properties
that
are
reversed
twice,
execute
for
each
of
its
property
and
item
the
@reverse
:
@reverse
member,
create
one
and
set
its
value
to
@reverse
member
in
result
using
the
variable
reverse
map
.
@reverse
:
invalid
reverse
property
value
has
been
detected
and
processing
is
aborted.
@language
and
value
is
a
JSON
object
invalid
language
map
value
@list
@value
@language
-lowercased
language
).
@index
and
value
is
a
JSON
object
then
value
is
expanded
from
an
index
map
as
follows:
@index
,
add
the
key-value
pair
(
@index
-
index
)
to
item
.
@list
and
expanded
value
is
not
already
a
@id
@list
-
expanded
value
.
@reverse
member,
create
@id
@reverse
member
invalid
reverse
property
value
algorithm.
has
been
detected
and
processing
is
aborted.
@value
:
@value
,
@language
,
@type
,
and
@index
.
It
@language
key
and
the
@type
key.
Otherwise,
an
invalid
value
object
error
has
been
detected
and
processing
is
aborted.
@value
key
is
null
,
then
set
result
to
@value
member
is
not
a
string
and
result
contains
the
key
@language
,
an
invalid
language-tagged
value
error
has
been
detected
(only
strings
can
be
language-tagged)
and
processing
is
aborted.
@type
member
and
its
value
is
not
a
invalid
typed
value
error
has
been
detected
and
processing
is
aborted.
@type
and
its
@set
or
@list
:
@index
.
Otherwise,
an
invalid
set
or
list
object
error
has
been
detected
and
processing
is
aborted.
@set
,
then
set
result
to
@language
,
set
result
to
null
.
@graph
,
drop
free-floating
values
as
follows:
@value
or
@list
,
set
result
to
null
.
0
@id
,
set
result
to
null
.
If,
after
the
above
algorithm
is
run,
the
result
is
a
JSON
object
that
contains
only
an
@graph
and
key,
set
the
result
to
the
value
of
@graph
's
value.
Otherwise,
if
the
result
is
null
,
set
it
to
an
empty
array
.
Finally,
if
the
result
is
not
an
array
,
then
set
the
result
to
an
array
containing
only
the
result.
Some values in JSON-LD can be expressed in a compact form . These values are required to be expanded at times when processing JSON-LD documents. A value is said to be in expanded form after the application of this algorithm.
prefix
This
section
is
non-normative.
If
active
property
has
a
type
mapping
in
the
active
context
set
to
_:t
@id
by
default.
or
@vocab
,
a
JSON
object
with
a
single
member
@id
whose
values
is
the
result
of
using
the
IRI
Expansion
algorithm
on
value
is
returned.
Otherwise,
the
result
will
be
a
JSON
object
containing
an
@value
member
whose
value
is
the
passed
value
.
Additionally,
an
@type
member
will
be
included
if
there
is
a
type
mapping
associated
with
the
active
property
or
an
@language
member
if
value
is
a
string
and
there
is
language
mapping
associated
with
the
active
property
.
The
algorithm
takes
three
required
inputs:
an
active
context
,
an
active
property
,
and
a
single
input
variable
identifier
which
might
be
null
.
value
to
expand.
@id
,
return
a
new
JSON
object
containing
a
single
key-value
pair
where
the
key
is
@id
and
the
value
is
@vocab
,
return
a
new
@id
and
1
.
@value
member
whose
value
is
set
to
value
.
@type
member
to
result
and
set
its
value
to
the
value
associated
with
the
type
mapping
.
@language
to
result
and
set
its
value
to
@language
to
result
and
set
its
value
to
the
default
language
.This algorithm compacts a JSON-LD document, such that the given context is applied. This must result in shortening any applicable IRIs to terms or compact IRIs , any applicable keywords to keyword aliases , and any applicable JSON-LD values expressed in expanded form to simple values such as strings or numbers .
This section is non-normative.
Starting with its root element , we can process the JSON-LD document recursively, until we have a fully compacted result . When compacting an element , we can treat each one differently according to its type, in order to break down the problem:
@index
or
@language
maps.
The
final
output
is
a
JSON
object
with
a
@context
key,
if
a
context
was
given,
where
the
JSON
object
is
either
result
or
a
wrapper
for
it
where
result
appears
as
the
value
of
an
(aliased)
@graph
key
because
result
contained
two
or
more
items
in
an
array
.
The
algorithm
takes
four
five
required
input
variables:
an
active
context
,
an
inverse
context
,
an
active
property
,
and
an
element
to
be
compacted.
compacted,
and
a
flag
compactArrays
.
To
begin,
the
active
context
is
set
to
the
result
of
performing
Context
Processing
on
the
passed
context
,
,
the
inverse
context
is
set
to
the
result
of
creating
an
inverse
context
from
performing
the
Inverse
Context
Creation
algorithm
on
active
context
,
the
active
property
is
set
to
null
,
and
element
is
set
to
the
result
of
performing
the
Expansion
Algorithm
algorithm
on
the
JSON-LD
input
,
and,
if
not
passed,
compactArrays
is
set
to
true
.
1
),
active
property
has
no
container
mapping
in
active
context
,
and
compactArrays
@value
or
@id
@reverse
,
otherwise
to
false
.
@id
,
compact
or
@type
:
@type
,
@type
array
:
1
),
then
set
compacted
value
@graph
,
compact
@reverse
:
@reverse
for
active
property
,
and
expanded
value
for
element
.
compactArrays
is
false
and
value
is
not
an
array
,
set
value
to
a
new
array
containing
only
value
.
@reverse
for
iri
.
@index
and
active
property
has
a
container
mapping
in
active
context
that
is
@index
,
then
the
compacted
result
will
be
inside
of
an
@index
container,
drop
the
@index
property
by
continuing
to
the
next
expanded
property
.
@index
,
@value
,
or
@language
:
@list
,
otherwise
pass
the
key's
associated
value
for
element
.
@list
:
@list
for
iri
,
and
@index
,
then
add
a
key-value
pair
to
compacted
item
where
the
key
is
the
result
of
the
IRI
Compaction
algorithm
,
passing
active
@index
as
iri
,
and
the
associated
with
the
@index
key
in
expanded
item
as
value
.
compaction
to
list
of
lists
error
has
been
detected
and
processing
is
aborted.
@language
or
@annotation
@index
:
@language
and
compacted
item
contains
the
key
@value
,
then
set
compacted
item
to
the
value
associated
with
its
@value
key.
compactArrays
is
false
,
container
is
@language
@set
or
@annotation
@list
,
or
expanded
property
is
@list
@graph
and
compacted
item
If,
after
the
Value
Compaction
algorithm
passing
index
as
containerValue
,
then
compact
outlined
above
is
run,
the
result
result
is
an
array
,
replace
it
by
recursively
invoking
this
algorithm
passing
with
a
copy
new
JSON
object
with
a
single
member
whose
key
is
the
result
of
using
the
IRI
Compaction
algorithm
,
passing
active
context
,
inverse
context
,
and
@graph
as
iri
and
whose
value
is
the
active
property
.
If
no
index
array
result
.
Finally,
if
a
context
has
been
passed,
add
an
@context
member
exists
in
the
mapObject
create
one
to
result
and
set
its
value
to
item
;
otherwise
append
item
to
the
index
member
(converting
passed
context
.
When there is more than one term that could be chosen to compact an IRI , it has to be ensured that the term selection is both deterministic and represents the most context-appropriate choice whilst taking into consideration algorithmic complexity.
In
order
to
make
term
selections,
the
concept
of
an
array
inverse
context
is
introduced.
An
inverse
context
is
essentially
a
reverse
lookup
table
that
maps
container
mappings
,
type
mappings
,
and
language
mappings
to
a
simple
term
for
a
given
active
context
.
A
inverse
context
only
needs
to
be
generated
for
an
active
context
if
it
is
not
one
already).
Continue
with
being
used
for
compaction
.
To
make
use
of
an
inverse
context
,
a
list
of
preferred
container
mappings
and
the
next
property
-
type
mapping
or
language
mapping
are
gathered
for
a
particular
value
pair
from
element
.
If
associated
with
an
IRI
.
These
parameters
are
then
fed
to
the
Term
Selection
algorithm
,
which
will
find
the
term
that
most
appropriately
matches
the
value's
mappings.
item
This
section
is
a
JSON
object
non-normative.
To
create
an
inverse
context
having
for
a
@list
member,
compact
given
active
context
,
each
term
in
the
value
active
context
is
visited,
ordered
by
length,
shortest
first
(ties
are
broken
by
choosing
the
lexicographically
least
term
).
For
each
term
,
an
entry
is
added
to
the
inverse
context
for
each
possible
combination
of
container
mapping
and
type
mapping
or
language
mapping
that
member
by
recursively
invoking
this
algorithm
passing
would
legally
match
the
term
.
Illegal
matches
include
differences
between
a
copy
value's
type
mapping
or
language
mapping
and
that
of
the
active
context
term
.
If
a
term
has
no
container
mapping
,
type
mapping
,
or
language
mapping
(or
some
combination
of
these),
then
it
will
have
an
entry
in
the
inverse
context
,
using
the
special
key
@none
.
This
allows
the
Term
Selection
algorithm
to
fall
back
to
choosing
more
generic
terms
when
a
more
specifically-matching
term
is
not
available
for
a
particular
IRI
and
value
combination.
The
algorithm
takes
one
required
input:
the
active
property
context
ensuring
that
the
result
inverse
context
is
being
created
for.
@none
.
If
the
active
@none
.
If
@language
and
its
value
is
a
new
empty
JSON
object
,
the
second
member
is
@type
and
its
value
is
a
new
empty
JSON
object
.
@type
@reverse
member,
create
one
and
set
its
value
to
the
term
being
processed.
false
@type
@list
@language
@null
;
otherwise
set
it
@language
member
in
type/language
map
using
the
variable
language
map
.
@none
member,
create
one
and
set
its
value
to
the
@graph
@type
@context
@none
This
section
defines
an
algorithm
for
transforming
compacts
an
IRI
to
a
term
or
compact
IRI
.
If
,
or
a
keyword
to
a
keyword
alias
.
A
value
that
is
associated
with
the
IRI
may
be
passed
in
order
to
assist
in
selecting
the
most
context-appropriate
term
.
This section is non-normative.
If
the
passed
IRI
is
null
,
we
simply
return
null
.
Otherwise,
we
first
try
to
find
a
term
that
the
IRI
or
keyword
can
be
compacted
to
if
it
is
relative
to
active
context's
vocabulary
mapping
.
In
order
to
select
the
most
appropriate
term
,
we
may
have
to
collect
information
about
the
passed
value
.
This
information
includes
whic
container
mappings
would
be
preferred
for
expressing
the
value
,
and
what
its
type
mapping
or
language
mapping
is.
For
JSON-LD
lists
,
the
type
mapping
or
language
mapping
will
be
chosen
based
on
the
most
specific
values
that
work
for
all
items
in
the
list.
Once
this
information
is
gathered,
it
is
used
passed
to
choose
the
best
matching
Term
Selection
algorithm
,
which
will
return
the
most
appropriate
term
to
use.
If no term was found that could be used to compact the IRI , then an attempt is made to find a compact IRI to use. If there is no appropriate compact IRI , then, if the IRI is relative to active context's vocabulary mapping , then it is used. Otherwise, it is transformed to a relative IRI using the document's base IRI . Finally, if the IRI or keyword still could not be compacted, it is returned as is.
This
algorithm
takes
three
mandatory
required
inputs
and
two
three
optional
parameters.
inputs.
The
mandatory
parameters
are
the
iri
to
be
compacted,
required
inputs
an
active
context
,
and
an
inverse
context
.
Optionally
it
is
possible
,
and
the
iri
to
pass
be
compacted.
The
optional
inputs
are
a
value
and
associated
with
the
iri
,
a
vocabRelative
vocab
flag
which
specifies
whether
the
passed
iri
should
be
compacted
using
the
active
context's
vocabulary
mapping
.
If
the
vocabRelative
,
and
a
reverse
flag
which
specifies
whether
a
reverse
property
is
being
compacted.
If
not
passed,
value
is
set
to
null
and
vocab
and
reverse
are
both
set
it
defaults
to
false
.
@none
.
@set
@language
,
@null
.
These
two
variables
will
keep
track
of
the
preferred
type
mapping
or
language
mapping
for
a
term
,
based
on
what
is
compatible
with
value
.
@annotation
@index
,
then
append
the
value
@index
@type
and
typeLanguageValue
,
type/language
value
to
@id
.
@reverse
,
and
append
@set
to
containers
.
@type
@index
@type
@list
@type
@list
@language
@none
and
@none
.
@language
member
of
value
.
@value
:
@annotation
member,
@language
,
then
set
@value
member
is
is
a
string
,
@type
,
set
@null
.
@list
member,
@id
.
@list
@value
,
then
set
common
language
to
@none
@list
@none
@none
and
common
type
is
@none
,
then
stop
processing
items
in
the
@none
.
@list
@none
.
@none
@type
and
type/language
value
to
common
type
.
@list
@language
and
does
not
contain
the
key
@index
,
then
set
null
@language
@set
@type
,
then
set
type/language
value
to
its
associated
value
and
set
type/language
to
@null
@type
.
@type
and
@null
@id
.
@set
to
@none
to
containers
.
This
represents
the
non-existence
of
@null
.
@null
.
@reverse
,
append
@reverse
to
preferred
values
.
@id
or
@reverse
and
value
has
an
@id
member:
@id
key
in
term
@id
@vocab
,
@id
,
and
@none
,
in
that
order,
to
preferred
values
.
@id
,
@vocab
,
and
@none
,
in
that
order,
to
preferred
values
.
@none
,
in
that
order,
to
preferred
values
.:
),
then
continue
:
An
active
context
as
produced
by
the
Context
Processing
algorithm
is
very
efficient
for
expanding
terms
and
compact
IRIs
to
IRIs
but
is
of
limited
use
for
This
algorithm,
invoked
via
the
opposite
operation:
IRI
compaction
.
Hence,
this
Compaction
algorithm
introduces
the
notion
,
makes
use
of
an
active
context's
inverse
context
which
brings
to
find
the
same
efficiency
term
that
is
best
used
to
compact
an
IRI
compaction
.
An
inverse
context
a
tree
of
JSON
objects
which
allow
to
efficiently
select
a
term
for
Other
information
about
a
value
associated
with
the
IRI
-value
pair.
The
value
takes
an
active
context
is
given,
including
which
container
mappings
and
returns
which
type
mapping
or
language
mapping
would
be
best
used
to
express
the
corresponding
inverse
context
.
value.
defaultLanguage
This
section
is
non-normative.
to
active
The
inverse
context's
default
language
if
there
is
one;
otherwise
set
it
to
@null
.
For
each
term
definition
in
the
active
context
perform
the
following
steps:
If
entry
for
the
term's
IRI
mapping
is
set
will
be
first
searched
according
to
null
continue
with
the
next
term
definition
.
Set
preferred
container
to
the
value
of
mappings
,
in
the
term's
order
that
they
are
given.
Amongst
terms
with
a
matching
container
mapping
,
preference
will
be
given
to
those
with
a
matching
type
mapping
or
@null
if
no
such
language
mapping
exists.
,
over
those
without
a
type
mapping
or
language
mapping
.
If
the
there
is
no
term
is
with
a
property
generator
,
set
termType
to
propertyGenerators
.
Otherwise
set
set
termType
to
term
and
append
the
term
matching
container
mapping
to
then
the
term
member
of
the
JSON
object
for
without
a
container
mapping
that
matches
the
term's
given
type
mapping
IRI
in
inverse
context
or
language
mapping
(append
term
to
inverseContext[iri]['term']
).
For
each
iri
mapped
to
the
is
selected.
If
there
is
still
no
selected
term
,
perform
the
following
steps:
If
the
then
a
term
has
a
with
no
type
mapping
to
type
,
append
the
term
or
language
mapping
to
inverseContext[iri][container]['@type'][type][termType]
,
e.g.,
inverseContext['http://...']['@list']['@type']['http://...']['term']
.
Otherwise,
will
be
selected
if
the
available.
No
term
will
be
selected
that
has
a
language
conflicting
type
mapping
store
the
associated
language
in
language
,
replacing
null
with
@null
.
Then
append
the
term
to
inverseContext[iri][container]['@language'][language][termType]
,
e.g.,
inverseContext['http://...']['@list']['@language']['de']['term']
.
Otherwise
append
the
term
to
inverseContext[iri][container]['@null']['@null'][termType]
as
well
as
inverseContext[iri][container]['@language'][defaultLanguage][termType]
to
take
the
default
language
into
consideration
for
terms
without
explicit
or
language
mapping
.
Remove
all
but
Ties
between
terms
that
have
the
same
mappings
are
resolved
by
first
choosing
the
shortest
terms,
and
lexicographically
least
term
in
each
term
member
in
inverse
context
.
The
result
is
thus
a
single
string
value.
Finally,
sort
then
by
choosing
the
array
associated
with
every
propertyGenerators
member
in
inverse
context
lexicographically
(shortest
terms
come
first).
5.11
Inverse
Context
Query
Algorithm
It
is
possible
that
multiple
terms
least
term.
Note
that
differ
in
their
container
,
type
,
or
language
mapping
these
ties
are
mapped
to
resolved
automatically
because
they
were
previously
resolved
when
the
same
IRI
.
The
purpose
of
this
Inverse
Context
Creation
algorithm
is
was
used
to
query
create
the
inverse
context
to
return
either
the
best
matching
term
,
or
a
list
of
potential
property
generators
along
with
a
term
to
fall
back
to
if
none
of
the
property
generators
can
be
applied.
.
This
algorithm
takes
has
five
required
inputs.
They
are:
an
inverseContextSubtree
,
inverse
context
,
a
queryPath
as
generated
by
the
keyword
or
IRI
Compaction
algorithm
and
a
level
parameter
which
is
initialized
to
0
if
nothing
else
is
passed.
The
algorithm
returns
either
iri
,
an
array
containers
that
represents
an
ordered
list
of
preferred
container
mappings
,
a
string
representing
the
best
matching
term
or
type/language
that
indicates
whether
to
look
for
a
JSON
object
term
consisting
of
a
propertyGenerators
member,
containing
with
a
sorted
array
matching
type
mapping
of
potential
property
generators
or
language
mapping
,
and
an
optional
term
member
containing
a
term
array
to
fall
back
to
if
none
representing
an
ordered
list
of
preferred
values
for
the
property
generators
type
mapping
can
be
applied.
or
language
mapping
to
look
for.
Expansion
transforms
all
values
into
expanded
form
in
JSON-LD.
This
algorithm
does
the
opposite,
it
compacts
an
algorithm
according
the
term
definition
of
the
passed
active
property
.
After
performs
the
application
of
this
algorithm
opposite
operation,
transforming
a
value
is
said
to
be
in
into
compacted
form
.
This
algorithm
takes
compacts
a
value
,
an
according
to
the
term
definition
in
the
given
active
context
,
an
inverse
context
,
an
that
is
associated
with
the
value's
associated
active
property
,
and
an
optional
containerValue
.
.
containerValue
This
section
is
non-normative.
The
value
to
compact
has
been
passed,
either
an
@id
or
an
@value
member.
For
the
former
case,
if
the
type
mapping
of
active
property
has
a
container
mapping
is
set
to
or
@annotation
@id
@vocab
and
value
has
consists
of
only
of
an
member
@annotation
@id
which
equals
containerValue
,
remove
that
member.
If
value
is
a
JSON
object
and,
if
if
the
container
mapping
having
a
single
member
of
active
property
is
set
to
,
@id
@index
return
an
@index
member,
value
can
be
compacted
to
a
string
by
returning
the
result
of
performing
using
the
IRI
Compaction
algorithm
on
that
member's
value.
to
compact
the
value
associated
with
the
@id
member.
Otherwise,
if
value
cannot
be
compacted
and
is
a
JSON
object
having
a
returned
as
is.
For
the
latter
case,
it
might
be
possible
to
compact
value
just
into
the
value
associated
with
the
@value
member,
perform
the
following
steps:
If
member.
This
can
be
done
if
the
active
property
has
a
matching
type
mapping
or
language
mapping
and
value
has
a
corresponding
there
is
either
no
@type
@index
member,
remove
member
or
the
container
mapping
of
active
property
is
set
to
.
It
can
also
be
done
if
@type
@index
@value
is
the
only
member
from
in
value
.
Otherwise,
if
(apart
an
@index
member
in
case
the
container
mapping
of
active
property
has
is
set
to
@index
)
and
either
its
associated
value
is
not
a
string
,
there
is
no
default
language
,
or
there
is
an
explicit
null
language
mapping
for
the
active
property
.
This algorithm has four required inputs: an active context , an inverse context , an active property , and a value to be compacted.
@language
@index
@language
member
from
@index
,
decrease
number
members
by
1
.
2
,
return
value
@id
member:
1
and
the
type
mapping
of
active
property
@language
@id
,
return
the
result
of
using
the
IRI
compaction
algorithm
,
passing
active
context
,
inverse
context
,
and
the
value
@language
@id
member
1
and
the
type
mapping
of
active
property
is
set
to
@vocab
,
return
the
result
of
using
the
IRI
compaction
algorithm
,
passing
active
context
,
inverse
context
,
the
value
of
the
@id
member
for
iri
,
and
true
for
vocab
.
@type
member
whose
value
matches
the
type
mapping
@value
member
of
value
.
@language
@language
@value
member
1
and
either
the
value
of
@value
member
is
not
a
string
,
or
the
active
context
has
no
default
language
,
or
the
language
mapping
of
active
property
is
set
to
null
,,
return
@value
This
algorithm
checks
if
a
specific
value
exists
for
flattens
an
expanded
JSON-LD
document
by
collecting
all
IRIs
properties
of
a
node
associated
with
in
a
property
generator
single
JSON
object
and
if
so,
it
removes
them.
The
algorithm
takes
five
parameters:
element
,
property
,
value
,
active
context
,
active
property
.
For
each
item
propertyGenerator
of
the
array
labeling
all
blank
nodes
which
is
the
value
with
blank
node
identifiers
.
This
resulting
uniform
shape
of
the
propertyGenerators
member
of
active
property
perform
document,
may
drastically
simplify
the
following
steps:
Check
that
a
member
exists
for
each
code
required
to
process
JSON-LD
data
in
certain
applications.
associated
with
the
propertyGenerator
.
If
value
This
section
is
non-normative.
First,
a
node
map
is
not
null
also
check
whether
each
of
those
members
that
contains
value
.
Values
are
considered
to
be
equal
if
they
are
of
the
same
type
and
have
generated
using
the
same
value(s);
node
objects
Node
Map
Generation
algorithm
are
considered
to
be
equal
if
which
collects
all
members
match,
except
if
no
@id
member
exists
(i.e.,
it
is
an
unlabeled
blank
node
,
in
that
case
properties
of
a
node
objects
are
never
considered
to
be
equal.
If
that's
not
the
case,
continue
with
in
a
single
JSON
object
.
In
the
next
propertyGenerator
.
Otherwise,
remove
value
from
every
member.
If
step,
the
resulting
value
of
a
member
node
map
is
an
empty
array
,
remove
the
member
altogether
from
element
.
Return
propertyGenerator
.
Return
the
value
of
the
term
member
of
active
property
since
no
matching
property
generator
converted
to
a
JSON-LD
document
in
flattened
document
form
.
Finally,
if
a
context
has
been
found.
passed,
the
flattened
document
is
compacted
using
the
Compaction
algorithm
before
being
returned.
The
algorithm
takes
two
input
variables,
an
element
to
flatten
and
a
an
optional
context
used
to
compact
the
flattened
document.
If
not
passed,
context
is
set
to
null
.
@default
and
whose
value
is
an
empty
JSON
object
.
@default
member
of
@default
,
perform
the
following
steps:
@id
member
whose
value
is
set
to
@graph
member
to
entry
and
set
it
to
an
empty
array
@graph
member
of
entry
.
@graph
keyword
(or
its
alias)
at
the
top-level,
even
if
the
context
is
empty
or
if
there
is
only
one
element
to
put
in
the
@graph
array
.
This
ensures
that
the
returned
document
has
a
deterministic
structure.
This
algorithm
creates
a
JSON
object
nodeMap
node
map
holding
an
indexed
representation
of
the
graphs
and
nodes
represented
in
the
passed,
passed
expanded
document.
All
nodes
that
are
not
uniquely
identified
by
an
IRI
get
assigned
a
(new)
blank
node
identifier
.
The
resulting
nodeMap
node
map
will
have
a
member
for
every
graph
in
the
document
whose
value
is
another
object
with
a
member
for
every
node
represented
in
the
document.
The
default
graph
is
stored
under
the
@default
member,
all
other
graphs
are
stored
under
their
graph
name.
name
.
This section is non-normative.
The
algorithm
recursively
runs
over
an
expanded
JSON-LD
document
to
collect
all
properties
of
a
node
in
a
single
JSON
object
.
The
algorithm
constructs
a
JSON
object
node
map
whose
keys
represent
the
graph
names
used
in
the
document
(the
default
graph
is
stored
under
the
key
@default
)
and
whose
associated
values
are
JSON
objects
which
index
the
nodes
in
the
graph
.
If
a
property's
value
is
a
node
object
,
it
is
replace
by
a
node
object
consisting
of
only
an
@id
member.
If
a
node
object
has
no
@id
member
or
it
is
identified
by
a
blank
node
identifier
,
a
new
blank
node
identifier
is
generated.
This
relabeling
of
blank
node
identifiers
is
also
be
done
for
properties
and
values
of
@type
.
The
algorithm
takes
as
input
an
expanded
JSON-LD
document
element
and
a
reference
to
a
JSON
object
nodeMap
.
node
map
.
Furthermore
it
has
the
optional
parameters
active
graph
(which
defaults
to
@default
),
an
active
subject
,
active
property
,
and
a
reference
to
a
JSON
object
list
.
The
nodeMap
must
be
initialized
to
a
JSON
object
consisting
of
a
single
member
whose
name
corresponds
with
.
If
not
passed,
active
graph
subject
,
active
property
,
and
whose
value
is
an
empty
JSON
object
list
are
set
to
null
.
@type
member,
perform
for
each
item
the
following
steps:
@id
@value
member,
perform
the
following
steps:
@list
member
of
list
@list
member,
perform
the
following
steps:
@list
whose
value
is
initialized
to
an
empty
array
.
@list
member
@id
member,
@id
whose
value
is
@id
whose
value
is
id
@list
member
of
list
@type
member,
merge
each
@type
member
of
@type
member
from
element
@annotation
@index
member,
set
the
@annotation
@index
member
of
@index
member
with
a
different
value,
CONFLICTING_ANNOTATION
conflicting
indexes
@index
member
from
element
.
@reverse
member:
@id
whose
value
is
id
.
@reverse
member
of
element
.
@annotation
@reverse
member
from
element
@graph
member,
recursively
invoke
this
algorithm
passing
the
value
of
the
@graph
member
@graph
member
from
element
This
specification
describes
algorithms
algorithm
is
used
to
transform
JSON-LD
documents
generate
new
blank
node
identifiers
or
to
relabel
an
array
of
RDF
quads
existing
blank
node
identifier
and
vice-versa.
Note
that
many
uses
of
JSON-LD
may
not
require
generation
to
avoid
collision
by
the
introduction
of
RDF.
new
ones.
This section is non-normative.
The
processing
algorithms
described
simplest
case
is
if
there
exists
already
a
blank
node
identifier
in
this
section
are
provided
the
identifier
map
for
the
passed
identifier
,
in
order
to
demonstrate
how
which
case
it
is
simply
returned.
Otherwise,
a
new
blank
node
identifier
is
generated
by
concatenating
the
string
_:b
and
the
counter
.
If
the
passed
identifier
is
not
null
,
an
entry
is
created
in
the
identifier
map
associating
the
identifier
with
the
blank
node
identifier
.
Finally,
the
counter
is
increased
by
one
might
implement
and
the
new
blank
node
identifier
is
returned.
The
algorithm
takes
a
JSON-LD
single
input
variable
identifier
which
may
be
null
.
Between
its
executions,
the
algorithm
needs
to
RDF
processor.
Conformant
implementations
are
only
required
keep
an
identifier
map
to
produce
the
same
type
relabel
existing
blank
node
identifiers
consistently
and
number
of
quads
a
counter
to
generate
new
blank
node
identifiers
.
The
counter
is
initialized
to
0
by
default.
_:b
and
counter
.
1
.
This
section
describes
algorithms
to
transform
a
JSON-LD
document
to
an
RDF
dataset
and
vice
versa.
The
algorithm
below
is
algorithms
are
designed
for
in-memory
implementations
with
random
access
to
JSON
object
elements.
A
conforming
JSON-LD
processor
implementing
RDF
conversion
must
implement
a
processing
algorithm
that
results
in
the
same
set
of
RDF
quads
that
Throughout
this
section,
the
following
algorithm
generates:
vocabulary
prefixes
are
used
in
compact
IRIs
:
Prefix | IRI |
---|---|
rdf | http://www.w3.org/1999/02/22-rdf-syntax-ns# |
rdfs | http://www.w3.org/2000/01/rdf-schema# |
xsd | http://www.w3.org/2001/XMLSchema# |
The
algorithm
takes
four
input
variables:
This
algorithms
converts
a
element
JSON-LD
document
to
be
converted,
an
active
subject
,
active
property
and
graph
name
RDF
dataset
.
To
begin,
the
active
subject
,
active
property
RDF
does
not
currently
allow
a
blank
node
identifier
are
set
to
null
,
and
be
used
as
a
graph
name
.
element
This
section
is
non-normative.
The
JSON-LD
document
is
set
expanded
and
converted
to
a
node
map
using
the
result
of
performing
Node
Map
Generation
algorithm
.
This
allows
each
graph
represented
within
the
Expansion
Algorithm
on
document
to
be
extracted
and
flattened,
making
it
easier
to
process
each
node
object
.
Each
graph
from
the
JSON-LD
input
node
map
is
processed
to
extract
RDF
triples
,
to
which
any
(non-default)
graph
name
is
expected
applied
to
be
a
a
well-formed
JSON-LD
document
as
defined
create
an
RDF
dataset
.
Each
node
object
in
[
the
node
map
has
an
@id
member
which
corresponds
to
the
RDF
subject
,
the
other
members
represent
RDF
predicates
.
Each
member
value
is
either
an
JSON-LD
IRI
].
This
removes
any
existing
context
or
blank
node
identifier
or
can
be
transformed
to
allow
an
RDF
literal
to
generate
an
RDF
triple
.
Lists
are
transformed
into
an
RDF
Collection
using
the
given
context
List
to
be
cleanly
applied.
RDF
Conversion
algorithm.
The algorithm takes a JSON-LD document element and returns an RDF dataset .
@type
,
then
for
each
type
in
values
,
append
a
rdf:type
,
and
type
to
triples
.
@type
@list
@list
property
the
value
must
be
an
array
.
Process
its
value
as
a
list
as
described
in
List
Conversion
using
the
return
value
as
@default
,
add
triples
to
the
This
algorithm
takes
a
@id
property,
the
node
object
or
value
must
be
a
string
,
set
the
active
subject
object
and
transforms
it
into
an
RDF
resource
to
be
used
as
the
previously
expanded
value
(either
a
blank
node
object
or
of
an
RDF
triple
.
).
Otherwise,
if
element
This
section
is
non-normative.
does
not
have
a
@id
property,
set
Value
objects
are
transformed
to
RDF
literals
as
defined
in
the
active
subject
section
Data
Round
Tripping
whereas
node
objects
are
transformed
to
newly
generated
IRIs
or
blank
node
identifiers
.
Process
each
property
and
value
in
element
,
ordered
by
property
,
The
algorithm
takes
as
follows:
its
sole
argument
item
which
must
be
either
a
value
object
or
node
object
.
rdf:type
.
@id
member.
@value
member
in
item
.
@type
member
of
null
if
item
does
not
have
such
a
member.
xsd:boolean
.
xsd:integer
or
xsd:double
,
depending
on
if
the
value
contains
a
fractional
and/or
an
exponential
component.
xsd:string
or
rdf:langString
,
depending
on
if
item
has
an
@language
member.
@language
member
and
datatype
is
rdf:langString
,
then
add
the
value
associated
with
the
@language
key
as
the
language
of
literal
.
List
Conversion
is
the
process
of
taking
an
array
a
list
object
of
values
and
adding
them
to
a
newly
created
transforming
it
into
an
RDF
Collection
(see
as
defined
in
RDF
Semantics
[
RDF-SCHEMA
RDF-MT
])
by
linking
].
This section is non-normative.
For
each
element
of
the
list
using
a
new
blank
node
identifier
is
allocated
which
is
used
to
generate
rdf:first
and
triples
.
The
algorithm
returns
the
list
rdf:next
,
terminating
rdf:rest
with
head,
which
is
either
the
the
first
allocated
blank
node
identifier
or
rdf:nil
using
if
the
following
sequence:
list
is
empty.
The
algorithm
is
invoked
with
takes
two
inputs:
an
array
array
,
the
active
property
list
and
returns
a
value
to
be
used
as
an
active
object
empty
array
in
list
triples
used
for
returning
the
calling
location.
Note
This
algorithm
does
not
support
lists
containing
lists.
Issue
This
algorithm
hasn't
been
updated
yet.
generated
triples
.
rdf:nil
.
rdf:first
as
the
active
property
.
Process
,
and
the
rdf:nil
.
rdf:rest
,
and
rest
rdf:nil
if
bnodes
is
empty.
This algorithm converts an RDF dataset consisting of a default graph and zero or more named graphs into a JSON-LD document.
In
some
cases,
data
exists
natively
in
the
form
of
triples
or
or
quads
triples
;
for
example,
if
the
data
was
originally
represented
in
an
RDF
graph
or
triple/quad
store.
dataset
.
This
algorithm
is
designed
to
simply
translate
an
array
of
quads
triples
into
a
JSON-LD
document.
This algorithm does not support lists containing lists.
When
expanding
typed
values
This
section
is
non-normative.
Iterate
through
each
graph
in
the
dataset,
converting
RDF
Collections
having
into
a
datatype
of
xsd:string
,
the
@type
must
not
be
set
to
xsd:string
list
and
the
resulting
value
must
have
only
generating
a
@value
property.
JSON-LD
document
in
expanded
form
for
all
RDF
literals
,
IRIs
and
blank
node
identifiers
.
The
conversion
algorithm
takes
a
single
parameter
input
dataset
in
the
form
of
an
array
of
Quad
representations.
Issue
This
algorithm
hasn't
been
updated
yet.
an
RDF
dataset
.
nodeMap
and
listMap
,
each
,
whose
value
is
an
an
empty
JSON
object
.
@default
whose
value
is
set
to
reference
default
graph
.
nodeMap
member
of
default
graph
using
the
variable
default
graph
nodes
.
@default
,
otherwise
to
the
nodeMap
and
listMap
,
whose
value
is
an
an
empty
JSON
object
.
@id
whose
value
is
name
.
nodeMap
member
in
graph
object
using
the
variable
node
map
and
listMap
member
using
the
variable
list
map
.
rdf:rest
:
rdf:first
,
first
member
of
the
subject
member
of
list
map
to
the
rdf:rest
:
@id
rest
@id
rdf:type
,
and
object
is
@type
,
creating
an
entry
in
value
if
necessary.
Otherwise,
if
object
is
a
typed
value
and
the
useNativeTypes
head
member
of
the
object
listMap
member
in
graph
object
using
the
variable
list
map
.
listMap
member
of
graph
head
and
an
first
keys:
member
it
does
not
represent
the
head
of
a
list
.
Continue
with
the
next
key-value
pair.
head
member
in
entry
@id
@list
first
from
member
of
entry
rest
:
member
of
entry
is
not
rdf:nil
:
rest
member
of
entry
.
first
member
of
entry
to
the
@list
member
of
value
.
@graph
nodeMap
member
of
the
subject
member
of
graph
map
using
the
variable
node
map
.
@graph
member
of
node
.This algorithm transforms an RDF literal to a JSON-LD value object and a RDF blank node or IRI to an JSON-LD node object .
array
This
section
is
non-normative.
RDF literals are transformed to value objects as defined in the section Data Round Tripping whereas IRIs and blank node identifiers are transformed to node objects .
This algorithm takes as single input variable value that is converted to a JSON object .
rdf:nil
return
a
new
JSON
object
consisting
of
a
single
member
@list
whose
value
is
set
to
an
empty
array
.
This
is
behavior
is
required
by
the
Convert
from
RDF
algorithm
.
@id
whose
value
is
set
to
value
.
xsd:boolean
,
set
converted
value
to
true
if
the
lexical
form
of
value
matches
true
,
or
false
if
it
matches
false
.
xsd:integer
or
xsd:double
,
try
to
convert
the
literal
to
a
JSON
number
.
If
the
conversion
is
successful,
store
the
result
in
converted
value
.
@language
to
result
and
set
its
value
to
the
language
tag
of
value
.
xsd:string
which
is
ignored.
@value
to
result
whose
value
is
set
to
converted
value
.
@type
to
result
whose
value
is
set
to
type
.
When
converting
JSON-LD
to
RDF
JSON-native
types
such
as
numbers
and
booleans
are
automatically
coerced
to
xsd:integer
,
,
xsd:double
,
or
,
xsd:boolean
.
Implementers
.
must
MUST
ensure
that
the
result
is
in
canonical
lexical
form
.
A
canonical
lexical
form
is
a
set
of
literals
from
among
the
valid
set
of
literals
for
a
datatype
such
that
there
is
a
one-to-one
mapping
between
the
canonical
lexical
form
and
a
value
in
the
value
space
as
defined
in
[
XMLSCHEMA11-2
].
In
other
words,
every
value
must
MUST
be
converted
to
a
deterministic
string
representation.
The
canonical
lexical
form
of
an
integer
,
i.e.,
a
number
without
fractions
or
a
number
coerced
to
xsd:integer
,
is
a
finite-length
sequence
of
decimal
digits
(
,
0-9
)
with
an
optional
leading
minus
sign;
leading
zeroes
zeros
are
prohibited.
To
convert
the
number
in
JavaScript,
implementers
can
use
the
following
snippet
of
code:
(value).toFixed(0).toString()
The
canonical
lexical
form
of
a
double
,
i.e.,
a
number
with
fractions
or
a
number
coerced
to
xsd:double
,
consists
of
a
mantissa
followed
by
the
character
,
"E",
"E",
followed
by
an
exponent.
The
mantissa
must
MUST
be
a
decimal
number.
The
exponent
must
MUST
be
an
integer.
Leading
zeroes
zeros
and
a
preceding
plus
sign
(
+
)
are
prohibited
in
the
exponent.
If
the
exponent
is
zero,
it
must
be
indicated
by
E0
.
For
the
mantissa,
the
preceding
optional
plus
sign
is
prohibited
and
the
decimal
point
is
required.
Leading
and
trailing
zeroes
zeros
are
prohibited
subject
to
the
following:
number
representations
must
be
normalized
such
that
there
is
a
single
digit
which
is
non-zero
to
the
left
of
the
decimal
point
and
at
least
a
single
digit
to
the
right
of
the
decimal
point
unless
the
value
being
represented
is
zero.
The
canonical
representation
for
zero
is
0.0E0
.
xsd:double
's
value
space
is
defined
by
the
IEEE
double-precision
64-bit
floating
point
type
[
IEEE-754-1985
];
in
JSON-LD
the
mantissa
is
rounded
to
15
digits
after
the
decimal
point.
To convert the number in JavaScript, implementers can use the following snippet of code:
(value).toExponential(15).replace(/(\d)0*e\+?/,'$1E')
When
data
such
as
decimals
need
to
be
normalized,
JSON-LD
authors
should
not
use
values
that
are
going
to
undergo
automatic
conversion.
This
is
due
to
the
lossy
nature
of
xsd:double
values.
Authors
should
instead
use
the
expanded
object
form
to
set
the
canonical
lexical
form
directly.
The
canonical
lexical
form
of
the
boolean
values
true
and
false
are
the
strings
true
and
false
.
.
When
JSON-native
number
s,
are
type
coerced,
lossless
data
round-tripping
can
not
be
guaranted
guaranteed
as
rounding
errors
might
occur.
Additionally,
only
literals
typed
as
xsd:integer
,
,
xsd:double
,
and
,
xsd:boolean
are
automatically
converted
back
to
their
JSON-native
counterparts
in
when
converting
from
RDF
.
Some
JSON
serializers,
such
as
PHP's
native
implementation
in
some
versions,
backslash-escape
the
forward
slash
character.
For
example,
the
value
http://example.com/
would
be
serialized
as
http:\/\/example.com\/
.
This
is
problematic
as
other
JSON
parsers
might
not
understand
those
escaping
characters.
There
is
no
need
to
backslash-escape
forward
slashes
in
JSON-LD.
To
aid
interoperability
between
JSON-LD
processors,
a
JSON-LD
serializer
must
not
MUST
NOT
backslash-escape
forward
slashes.
This
API
provides
a
clean
mechanism
that
enables
developers
to
convert
JSON-LD
data
into
a
a
variety
of
output
formats
that
are
often
easier
to
work
with
in
various
programming
languages.
If
a
with.
A
conformant
JSON-LD
API
is
provided
in
a
programming
environment,
Processor
MUST
implement
the
entirety
of
the
following
API
must
be
implemented.
API.
The
JSON-LD
processor
Processor
interface
is
the
high-level
programming
structure
that
developers
use
to
access
the
JSON-LD
transformation
methods.
The
JSON-LD
API
signatures
are
the
same
across
all
programming
languages.
Due
to
the
fact
that
asynchronous
programming
is
uncommon
in
certain
languages,
developers
may
implement
a
processor
with
a
synchronous
interface
instead.
In
that
case,
the
callback
parameter
must
not
be
included
and
the
result
must
be
returned
as
a
return
value
instead.
It
is
important
to
highlight
that
conformant
JSON-LD
processors
must
not
MUST
NOT
modify
the
input
parameters.
If
an
error
is
detected,
the
callback
is
invoked
passing
a
JsonLdError
with
the
corresponding
error
code
and
processing
is
stopped.
[Constructor]
interface JsonLdProcessor {
void expand ((object or object[] or DOMString) input, JsonLdCallback
callback, optional JsonLdOptions
? options);
void compact ((object or object[] or DOMString) input, (object or DOMString)? context, JsonLdCallback
callback, optional JsonLdOptions
? options);
void flatten ((object or object[] or DOMString) input, (object or DOMString)? context, JsonLdCallback
callback, optional JsonLdOptions
? options);
};
compact
Compacts
the
given
input
using
the
context
according
to
the
steps
in
the
Compaction
Algorithm
algorithm
:
application/ld+json
or
application/json
or
if
the
document
cannot
be
parsed
as
JSON,
invoke
the
callback
passing
an
loading
document
failed
error.
expandContext
has
been
passed,
update
the
active
context
using
the
Context
Processing
algorithm
,
passing
the
expandContext
as
local
context
.
application/json
and
an
HTTP
Link
Header
[
RFC5988
]
using
the
http://www.w3.org/ns/json-ld#context
link
relation,
update
the
active
context
using
the
Context
Processing
algorithm
,
passing
the
context
referenced
in
the
HTTP
Link
Header
as
local
context
.
compactArrays
flag
in
options
.Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
input |
(
object
or
object[]
or
DOMString
)
|
✘ | ✘ | The JSON-LD object or array of JSON-LD objects to perform the compaction upon or an IRI referencing the JSON-LD document to compact. |
context |
(
object
or
DOMString
)
|
✔ | ✘ |
The
context
to
use
when
compacting
the
input
;
either
in
the
form
of
|
callback |
|
✘ | ✘ |
A
callback
that
is
called
when
processing
input
,
or
a
fatal
error
prevented
processing
from
completing.
|
options |
|
✔ | ✔ |
A
set
of
options
to
configure
the
|
void
expand
Expands
the
given
input
according
to
the
steps
in
the
Expansion
Algorithm
algorithm
:
application/ld+json
or
application/json
or
if
the
document
cannot
be
parsed
as
JSON,
invoke
the
callback
passing
an
loading
document
failed
error.
expandContext
has
been
passed,
update
the
active
context
using
the
Context
Processing
algorithm
,
passing
the
expandContext
as
local
context
.
application/json
and
an
HTTP
Link
Header
[
RFC5988
]
using
the
http://www.w3.org/ns/json-ld#context
link
relation,
update
the
active
context
using
the
Context
Processing
algorithm
,
passing
the
context
referenced
in
the
HTTP
Link
Header
as
local
context
.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
input |
(
object
or
object[]
or
DOMString
)
|
✘ | ✘ | The JSON-LD object or array of JSON-LD objects to perform the expansion upon or an IRI referencing the JSON-LD document to expand. |
callback |
|
✘ | ✘ |
A
callback
that
is
called
when
processing
input
,
or
a
fatal
error
prevented
processing
from
completing.
|
options |
|
✔ | ✔ | A set of options to configure the used algorithms such. This allows, e.g., to set the input document's base IRI . |
void
flatten
Flattens
the
given
input
and
compacts
it
using
the
passed
context
according
to
the
steps
in
the
Flattening
Algorithm
algorithm
:
application/ld+json
or
application/json
or
if
the
document
cannot
be
parsed
as
JSON,
invoke
the
callback
passing
an
loading
document
failed
error.
expandContext
has
been
passed,
update
the
active
context
using
the
Context
Processing
algorithm
,
passing
the
expandContext
as
local
context
.
application/json
and
an
HTTP
Link
Header
[
RFC5988
]
using
the
http://www.w3.org/ns/json-ld#context
link
relation,
update
the
active
context
using
the
Context
Processing
algorithm
,
passing
the
context
referenced
in
the
HTTP
Link
Header
as
local
context
.
0
)
to
be
used
by
the
Generate
Blank
Node
Identifier
algorithm
.
compactArrays
flag
in
options
(which
is
internally
passed
to
the
Compaction
algorithm
).
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
input |
(
object
or
object[]
or
DOMString
)
|
✘ | ✘ | The JSON-LD object or array of JSON-LD objects or an IRI referencing the JSON-LD document to flatten. |
context |
(
object
or
DOMString
)
|
✔ | ✘ |
The
context
to
use
when
compacting
the
flattened
input
;
either
in
the
form
of
|
callback |
|
✘ | ✘ |
A
callback
that
is
called
when
processing
input
,
or
a
fatal
error
prevented
processing
from
completing.
|
options |
|
✔ | ✔ | A set of options to configure the used algorithms such. This allows, e.g., to set the input document's base IRI . |
void
JSON-LD
processors
utilize
callbacks
in
order
to
return
exchange
information
in
an
asynchronous
manner
to
calling
with
applications.
This
section
details
the
parameters
sent
to
of
those
callbacks.
The
JsonLdCallback
is
called
when
processing
of
an
API
method
of
JsonLdProcessor
has
been
completed
completed,
either
successfully
or
been
terminated
by
an
a
fatal
error.
callback
JsonLdCallback
=
void
(
JsonLdProcessingError
JsonLdError
error
,
object
or
object
[]
document
);
JsonLdCallback
Parameters
error
of
type
JsonLdProcessingError
JsonLdError
document
of
type
array
of
object
or
object
The
LoadContextCallback
defines
the
callback
that
custom
context
loaders
have
to
implement
to
be
used
to
retrieve
remote
contexts.
callback
LoadContextCallback
=
void
(
DOMString
url
,
ContextLoadedCallback
callback
);
LoadContextCallback
Parameters
url
of
type
DOMString
callback
of
type
ContextLoadedCallback
The
ContextLoadedCallback
is
called
in
response
to
a
call
of
the
LoadContextCallback
.
callback
ContextLoadedCallback
=
void
(
JsonLdError
error
,
DOMString
url
,
DOMString
context
);
ContextLoadedCallback
Parameters
error
of
type
JsonLdError
JsonLdErrorCode
of
loading
remote
context
failed
.
url
of
type
DOMString
context
of
type
DOMString
This section describes datatype definitions used within the JSON-LD API.
The
JsonLdOptions
type
is
used
to
pass
various
options
to
the
JsonLdProcessor
methods.
dictionary JsonLdOptions {
DOMString base;
boolean compactArrays = true;
LoadContextCallback
loadContext;
object or DOMString expandContext = null;
DOMString processingMode = "json-ld-1.0";
};
JsonLdOptions
Members
base
of
type
DOMString
The
default
value
of
this
option
implies
that
all
IRIs
that
cannot
be
compacted
otherwise
are
transformed
to
relative
IRIs
during
compaction.
To
avoid
that
data
is
being
lost,
developers
thus
have
to
store
the
base
IRI
along
with
the
compacted
document.
This
might
be
problematic
in
practice
and
thus
the
default
behavior
might
be
changed
in
future.
Furthermore,
the
relationship
of
this
option
to
the
@base
keyword
(which
is
at
risk)
should
be
further
investigated.
compactArrays
of
type
boolean
,
defaulting
to
true
true
,
the
JSON-LD
processor
replaces
arrays
with
just
one
element
with
that
element
during
compaction.
If
set
to
false
,
all
arrays
will
remain
arrays
even
if
they
have
just
one
element.
expandContext
of
type
object
or
DOMString
,
defaulting
to
null
optimize
loadContext
of
type
false
LoadContextCallback
useNativeTypes
processingMode
of
type
true
"json-ld-1.0"
true
json-ld-1.0
,
the
JSON-LD
@type
json-ld
The
type
is
used
to
report
processing
errors
to
a
JsonLdProcessingError
JsonLdError
JsonLdCallback
.
dictionary JsonLdError {
JsonLdErrorCode
code;
DOMString? message;
};
JsonLdProcessingError
JsonLdError
Members
code
of
type
JsonLdErrorCode
message
of
type
DOMString
,
nullable
The
JsonLdErrorCode
represents
the
collection
of
valid
JSON-LD
error
codes.
represent
enum JsonLdErrorCode {
"loading document failed",
"list of lists",
"invalid @index value",
"conflicting indexes",
"invalid @id value",
"invalid local context",
"loading remote context failed",
"invalid remote context",
"recursive context inclusion",
"invalid base IRI",
"invalid vocab mapping",
"invalid default language",
"keyword redefinition",
"invalid term definition",
"invalid reverse property",
"invalid IRI mapping",
"cyclic IRI mapping",
"invalid keyword alias",
"invalid type mapping",
"invalid language mapping",
"colliding keywords",
"invalid container mapping",
"invalid type value",
"invalid value object",
"invalid value object value",
"invalid language-tagged string",
"invalid language-tagged value",
"invalid typed value",
"invalid set or list object",
"invalid language map value",
"compaction to list of lists",
"invalid reverse property map",
"invalid @reverse value",
"invalid reverse property value"
};
Enumeration description | |
---|---|
loading
document
failed
| The document could not be loaded or parsed as JSON. |
list
of
lists
|
A
|
invalid
@index
value
|
An
@index
member
was
encountered
whose
value
was
not
a
string
. |
conflicting
indexes
|
Multiple
conflicting
indexes
have
been
found
for
the
|
invalid
@id
value
|
An
@id
member
was
encountered
whose
value
was
not
a
string
. |
invalid
local
context
| In invalid local context was detected. |
loading
remote
context
failed
|
There was a problem encountered loading a remote context. |
invalid
remote
context
| No valid context document has been found for a referenced, remote context. |
recursive
context
inclusion
|
A
|
invalid
base
IRI
| An invalid base IRI has been detected, i.e., it is neither an absolute IRI nor null . |
invalid
vocab
mapping
| An invalid vocabulary mapping has been detected, i.e., it is neither an absolute IRI nor null . |
invalid
default
language
|
The
value
of
|
keyword
redefinition
| A keyword redefinition has been detected. |
invalid
term
definition
| An invalid term definition has been detected. |
invalid
reverse
property
| An invalid reverse property definition has been detected. |
invalid
IRI
mapping
| A local context contains a term that has an invalid or missing IRI mapping . |
cyclic
IRI
mapping
| A cycle in IRI mappings has been detected. |
invalid
keyword
alias
| An invalid keyword alias definition has been encountered. |
invalid
type
mapping
|
An
@type
member
in
a
term
definition
was
encountered
whose
value
could
not
be
expanded
to
an
absolute
IRI
. |
invalid
language
mapping
|
An
@language
member
in
a
term
definition
was
encountered
whose
value
was
neither
a
string
nor
null
and
thus
invalid.
|
colliding
keywords
|
Two
properties
which
expand
to
the
same
keyword
have
been
detected.
|
invalid
container
mapping
|
An
@container
member
was
encountered
whose
value
was
not
@list
,
@set
,
or
@index
. |
invalid
type
value
|
An
invalid
value
for
an
@type
member
has
been
detected,
i.e.,
the
value
was
neither
a
string
nor
an
array
of
strings
. |
invalid
value
object
| A value object with disallowed members has been detected. |
invalid
value
object
value
|
An
invalid
value
for
the
@value
member
of
a
value
object
has
been
detected,
i.e.,
it
is
neither
a
scalar
nor
null
. |
invalid
language-tagged
string
| A language-tagged string with an invalid language value was detected. |
invalid
language-tagged
value
| A number , true , or false with an associated language tag was detected. |
invalid
typed
value
|
A
typed
value
with
|
invalid
set
or
list
object
| A set object or list object with disallowed members has been detected. |
invalid
language
map
value
|
An
invalid
value
in
a
language
map
has
been
detected.
It
has
to
|
compaction
to
list
of
lists
| The compacted document contains a list of lists as multiple lists have been compacted to the same term. |
invalid
reverse
property
map
|
An
invalid
reverse
property
map
has
been
detected.
No
keywords
apart
from
@context
are
allowed
in
reverse
property
maps.
|
invalid
@reverse
value
|
An
invalid
value
for
an
@reverse
member
has
been
detected,
i.e.,
the
value
was
not
a
JSON
object
. |
invalid
reverse
property
value
| An invalid value for a reverse property has been detected. The value of an inverse property must be a node object . |
This section is non-normative.
A large amount of thanks goes out to the JSON-LD Community Group participants who worked through many of the technical issues on the mailing list and the weekly telecons - of special mention are Niklas Lindström, François Daoust, Lin Clark, and Zdenko 'Denny' Vrandečić. The editors would like to thank Mark Birbeck, who provided a great deal of the initial push behind the JSON-LD work via his work on RDFj. The work of Dave Lehn and Mike Johnson are appreciated for reviewing, and performing several implementations of the specification. Ian Davis is thanked for his work on RDF/JSON. Thanks also to Nathan Rixham, Bradley P. Allen, Kingsley Idehen, Glenn McDonald, Alexandre Passant, Danny Ayers, Ted Thibodeau Jr., Olivier Grisel, Josh Mandel, Eric Prud'hommeaux, David Wood, Guus Schreiber, Pat Hayes, Sandro Hawke, and Richard Cyganiak or their input on the specification.