Abstract

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
in
order
to
make
them
easier
to
work
with
in
programming
environments
like
JavaScript,
Python,
and
Ruby.
documents.
Restructuring
data
according
the
defined
transformations
often
dramatically
simplifies
its
usage.

Status
of
This
Document

This
section
describes
the
status
of
this
document
at
the
time
of
its
publication.
Other
documents
may
supersede
this
document.
A
list
of
current
W3C
publications
and
the
latest
revision
of
this
technical
report
can
be
found
in
the
W3C
technical
reports
index
at
http://www.w3.org/TR/.

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.
While
this
is
a
First
Public
Working
Draft
publication,
the
The
specification
has
undergone
significant
development,
review,
and
changes
during
the
course
of
the
last
18
months
and
is
more
mature
than
the
First
Public
Working
Draft
status
implies.
25
months.
There
are
currently
several
independent
five
interoperable
implementations
of
this
specification.
There
is
specification
and
a
fairly
complete
test
suite
and
a
live
JSON-LD
editor
that
is
capable
of
demonstrating
the
features
described
in
this
document.
While
development
on
implementations,
the
test
suite
and
the
live
editor
will
continue,
they
are
believed
to
be
mature
enough
to
be
integrated
into
a
non-production
system
at
this
point
in
time
with
the
expectation
that
they
could
be
used
in
a
production
system
within
the
next
year.
Issue
1
[
JSON-LD-TESTS
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
First
Public
Working
Draft
does
not
require
that
all
Working
Group
members
agree
on
the
content
of
the
document.
].

This
document
was
published
by
the
RDF
Working
Group
as
a
First
Public
Last
Call
Working
Draft.
This
document
is
intended
to
become
a
W3C
Recommendation.
If
you
wish
to
make
comments
regarding
this
document,
please
send
them
to
public-rdf-comments@w3.org
(
subscribe
,
archives
).
The
Last
Call
period
ends
11
May
2013.
All
feedback
is
comments
are
welcome.

The
Working
Group
welcomes
reports
of
implementations,
sent
to
the
comments
address.
If
we
gather
sufficient
evidence
of
interoperable
implementations,
the
group
may
request
to
skip
Call
for
Implementations
(Candidate
Recommendation)
drafts
and
have
the
next
round
of
publications
be
Proposed
Recommendations.

Publication
as
a
Last
Call
Working
Draft
does
not
imply
endorsement
by
the
W3C
Membership.
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
work
in
progress.

This
is
a
Last
Call
Working
Draft
and
thus
the
Working
Group
has
determined
that
this
document
has
satisfied
the
relevant
technical
requirements
and
is
sufficiently
stable
to
advance
through
the
Technical
Recommendation
process.

Software
developers
that
who
want
to
implement
processors
and
APIs
for
JSON-LD.
the
algorithms
to
transform
JSON-LD
documents.

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
syntax
defined
in
[
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
].

1.1
Contributing
There
are
a
number
of
ways
that
one
may
participate
in
the
development
of
this
specification:
If
you
want
to
make
sure
that
your
feedback
is
formally
addressed
by
the
RDF
Working
Group,
you
should
send
it
to
public-rdf-comments:
public-rdf-comments@w3.org
Ad-hoc
technical
discussion
primarily
occurs
on
the
public
community
mailing
list:
public-linked-json@w3.org
Public
JSON-LD
Community
Group
teleconferences
are
held
on
Tuesdays
at
1500UTC
every
week.
RDF
Working
Group
teleconferences
are
held
on
Wednesdays
at
1500UTC
every
week.
Participation
is
limited
to
RDF
Working
Group
members.
Specification
bugs
and
issues
should
be
reported
in
the
issue
tracker
if
you
do
not
want
to
send
an
e-mail
to
the
public-rdf-comments
mailing
list.
Source
code
for
the
specification
can
be
found
on
Github.
The
#json-ld
IRC
channel
is
available
for
real-time
discussion
on
irc.freenode.net.

2.
Introduction
Features

This
section
is
non-normative.

The
JSON-LD
Syntax
specification
[
JSON-LD
]
outlines
defines
a
language
that
may
be
used
syntax
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.

JSON-LD
uses
contexts
to
allow
Linked
Data
to
be
expressed
in
a
programming
environment
like
JavaScript,
Python
way
that
is
specifically
tailored
to
a
particular
person
or
Ruby.
application.
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
three
four
major
types
of
transformation
that
are
discussed
in
this
document;
compaction,
document:
expansion,
compaction,
flattening,
and
RDF
conversion.

2.1
Expansion

Software
algorithms
are
easiest
to
write
when
the
data
This
section
is
non-normative.

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
all
document,
it
is
easiest
to
remove
any
context
from
it
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:

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
are
IRI
s
to
their
fully
expanded
represented
in
a
regular
form.
The
second
is
These
goals
are
accomplished
by
expanding
all
properties
to
express
absolute
IRIs
and
by
expressing
all
values
in
arrays
in
expanded
form
.
To
transform
both
inputs
above
to
.
Expanded
form
is
the
same
representation,
most
verbose
and
regular
way
of
expressing
of
values
in
JSON-LD;
all
contextual
information
from
the
developer
could
do
document
is
instead
stored
locally
with
each
value.
Running
the
following:
function expansionCallback(output) {
console.log(output);
}
Expansion
algorithm
(
// the second parameter is 'null' because the developer does not wish to
// inject another context value
jsonld.expand(input1, null, expansionCallback);
jsonld.expand(input2,
null,
expansionCallback);
expand
The
output
for
both
calls
operation)
against
the
above
will
be:
examples
results
in
the
following
output:

Note
that
in
the
example
above;
output
above
all
context
definitions
have
been
removed,
all
term
terms
and
prefixes
compact
IRIs
have
been
expanded
to
full
IRIs,
absolute
IRIs
,
and
all
literal
JSON-LD
values
s
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.

2.2
Compaction

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
-
expressing
operation:
to
express
a
given
input
as
succinctly
as
possible.
While
expansion
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
ready
read
by
software
developers.
humans.

The
following
would
be
Running
the
Compaction
Algorithm
(
compact
operation)
given
the
context
supplied
above
against
the
JSON-LD
input
document
provided
above
would
result
of
in
the
call
above:
following
output:

Note
that
all
of
the
term
IRIs
s
have
been
compressed
and
compacted
to
terms
as
specified
in
the
context
,
which
has
been
injected
into
the
output.
While
compacted
output
is
most
useful
to
humans,
it
can
is
also
be
carefully
used
to
generate
structures
that
are
easy
to
use
for
program
against.
Compaction
enables
developers
to
program
against
as
well.
map
any
expanded
document
into
an
application-specific
compacted
document.
While
the
context
provided
above
mapped
http://xmlns.com/foaf/0.1/name
to
name
,
it
could
also
have
been
mapped
to
any
other
term
provided
by
the
developer.

2.3
Conversion
Flattening

This
section
is
non-normative.

While
expansion
ensures
that
a
document
is
in
a
uniform
structure,
flattening
goes
a
step
further
to
ensure
that
the
shape
of
the
data
is
deterministic.
In
expanded
documents,
the
properties
of
a
single
node
may
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
from
all
blank
nodes
are
labeled
with
a
blank
node
identifier
.
This
may
drastically
simplify
the
code
required
to
process
JSON-LD
data
in
certain
applications.

To
make
it
easier
for
humans
to
read
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:

Please
note
that
the
result
of
flattening
and
compacting
a
document
is
always
a
JSON
object
which
contains
an
@graph
member
that
represents
the
default
graph
.

2.4
RDF
Conversion

This
section
is
non-normative.

JSON-LD
can
be
used
to
losslessly
express
the
RDF
serialize
data
model
expressed
in
RDF
as
described
in
the
RDF
Concepts
document
[
RDF-CONCEPTS
RDF11-CONCEPTS
].
This
ensures
that
data
can
be
round-tripped
to
and
from
any
RDF
syntax,
like
N-Triples
or
TURTLE,
syntax
without
any
loss
in
the
fidelity
of
the
data.
Assume
fidelity.

A
developer
can
use
Using
the
JSON-LD
API
to
Convert
from
RDF
algorithm
a
developer
could
transform
the
markup
above
this
document
into
a
JSON-LD
document:
function conversionCallback(result)
{
console.log("JSON-LD Document: ", result);
};
jsonld.fromRDF(data,
conversionCallback,
{"format":
"ntriples"});
The
following
expanded
output
would
be
the
result
of
the
call
above:
JSON-LD:

Note
that
the
output
above,
above
could
easily
be
compacted
to
produce
the
following
using
the
technique
outlined
in
the
previous
section:
{
"@context": "http://json-ld.org/contexts/person.jsonld",
"@id": "http://manu.sporny.org/about/#manu",
"name": "Manu Sporny",
"homepage": "http://manu.sporny.org/"
}
Transforming
section.
It
is
also
possible
to
transform
the
object
above
JSON-LD
document
back
to
RDF
is
as
simple
as
calling
using
the
toRDF()
method:
Convert
to
RDF
algorithm
.

2.4
3.
Framing
Conformance

All
examples
and
Normalization
Issue
2
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
NOT
,
REQUIRED
,
SHOULD
,
SHOULD
NOT
,
RECOMMENDED
,
MAY
,
and
OPTIONAL
in
this
specification
are
to
be
interpreted
as
described
in
[
RFC2119
].

There
are
currently
two
other
API
methods
three
classes
of
products
that
are
in
active
development
and
were
not
ready
for
publication
at
the
time
this
document
was
published.
Framing
allows
a
developer
can
claim
conformance
to
force
a
different
layout
for
the
data
this
specification:
JSON-LD
Processors
,
JSON-LD
API
Implementations
,
and
effectively
perform
query-by-example
on
JSON-LD-RDF
Converters
.

A
conforming
JSON-LD
documents
-
this
Processor
is
most
useful
when
a
JSON-LD-based
REST
API
does
not
know
the
exact
form
of
system
which
can
perform
the
data
it
is
getting
in,
but
still
wants
to
operate
upon
it
if
some
bare
essentials
are
found
Expansion
,
Compaction
,
and
Flattening
operations
defined
in
the
data.
this
specification.

The
algorithms
in
various
programming
languages.
If
a
this
specification
are
generally
written
with
more
concern
for
clarity
than
efficiency.
Thus,
JSON-LD
Processors
and
API
is
provided
Implementations
may
implement
the
algorithms
given
in
a
programming
environment,
this
specification
in
any
way
desired,
so
long
as
the
entirety
of
end
result
is
indistinguishable
from
the
following
API
must
result
that
would
be
implemented.
obtained
by
the
specification's
algorithms.

3.1
General
Terminology

Issue
3
Note

The
intent
of
the
Working
Group
and
the
Editors
Implementers
can
partially
check
their
level
of
this
specification
is
conformance
to
eventually
align
terminology
used
in
this
document
with
specification
by
successfully
passing
the
terminology
used
in
test
cases
of
the
RDF
Concepts
document
to
JSON-LD
test
suite
[
JSON-LD-TESTS
].
Note,
however,
that
passing
all
the
extent
to
which
it
makes
sense
to
do
so.
In
general,
if
there
is
an
analogue
to
terminology
used
in
this
document
tests
in
the
RDF
Concepts
document,
the
preference
is
test
suite
does
not
imply
complete
conformance
to
use
this
specification.
It
only
implies
that
the
terminology
in
implementation
conforms
to
aspects
tested
by
the
RDF
Concepts
document.
test
suite.

4.
General
Terminology

The
This
document
uses
the
following
is
an
explanation
of
terms
as
defined
in
JSON
[
RFC4627
].
Refer
to
the
general
terminology
used
JSON
Grammar
section
in
this
document:
[
RFC4627
]
for
formal
definitions.

JSON
object

An
object
structure
is
represented
as
a
pair
of
curly
brackets
surrounding
zero
or
more
name-value
key-value
pairs.
A
name
key
is
a
string
.
A
single
colon
comes
after
each
name,
key,
separating
the
name
key
from
the
value.
A
single
comma
separates
a
value
from
a
following
name.
The
names
within
key.
In
contrast
to
JSON,
in
JSON-LD
the
keys
in
an
object
should
must
be
unique.

array

An
array
structure
is
represented
as
square
brackets
surrounding
zero
or
more
values
that
values.
Values
are
separated
by
commas.
In
JSON,
an
array
is
an
ordered
sequence
of
zero
or
more
values.
While
JSON-LD
uses
the
same
array
representation
as
JSON,
the
collection
is
unordered
by
default.
While
order
is
preserved
in
regular
JSON
arrays,
it
is
not
in
regular
JSON-LD
arrays
unless
specifically
defined
(see
Sets
and
Lists
in
the
JSON-LD
specification
[
JSON-LD
]).

string

A
string
is
a
sequence
of
zero
or
more
Unicode
(UTF-8)
characters,
wrapped
in
double
quotes,
using
backslash
escapes
(if
necessary).
A
character
is
represented
as
a
single
character
string.

number

A
number
is
similar
to
that
used
in
most
programming
languages,
except
that
the
octal
and
hexadecimal
formats
are
not
used
and
that
leading
zeros
are
not
allowed.

true
and
false

Values
that
are
used
to
express
one
of
two
possible
boolean
states.

null

Unless
otherwise
specified,
a
JSON-LD
processor
must
act
as
if
The
null
value.
A
key-value
pair
in
the
@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
was
never
declared
when
the
whose
value
equals
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.
If
@context
is
set
to
null
,

Furthermore,
the
active
context
following
terminology
is
reset
and
when
used
within
a
context
,
it
removes
any
definition
associated
with
the
key,
unless
otherwise
specified.
throughout
this
document:

subject
definition
keyword

A
JSON
object
used
to
represent
a
subject
and
one
or
more
properties
of
key
that
subject.
A
JSON
object
is
a
subject
definition
if
it
does
not
contain
they
keys
@value
,
@list
or
@set
and
it
has
one
or
more
keys
other
than
@id
.
specific
to
JSON-LD,
specified
in
the
section
subject
reference
Syntax
Tokens
and
Keywords
of
the
JSON-LD
specification
[
A
JSON
object
JSON-LD
used
to
reference
a
subject
having
only
the
@id
key.
].

Linked
Data
context

A
set
of
documents,
each
containing
a
representation
of
rules
for
interpreting
a
linked
data
graph
.
linked
data
graph
or
dataset
JSON-LD
document
as
specified
in
the
section
An
unordered
labeled
directed
graph,
where
node
s
are
subject
The
Context
s
or
object
of
the
JSON-LD
specification
[
JSON-LD
s,
and
edges
are
properties.
].

A
linked
data
named
graph
that
has
one
or
more
is
a
pair
consisting
of
an
IRI
that
are
used
to
refer
to
it.
or
blank
node
(the
graph
name
An
IRI
that
is
a
reference
to
)
and
a
named
JSON-LD
graph
.

default
graph

When
executing
an
algorithm,
The
default
graph
is
the
only
graph
where
data
should
be
placed
if
in
a
named
JSON-LD
document
which
has
no
graph
is
not
specified.
name
.

subject
JSON-LD
graph

Any
node
in
A
labeled
directed
graph,
i.e.,
a
linked
data
graph
set
of
nodes
with
at
least
one
outgoing
edge.
IRI
An
Internationalized
Resource
Identifier
connected
by
edges
,
as
described
specified
in
[
the
RFC3987
Data
Model
]).
object
A
node
in
a
linked
data
graph
with
at
least
one
incoming
edge.
property
An
edge
of
the
linked
data
graph
.
literal
An
object
with
a
label
that
is
not
an
IRI
.
quad
A
piece
section
of
information
that
contains
four
items;
a
subject
,
a
property
,
a
object
,
and
a
graph
name
.
context
A
JSON
object
that
contains
rules
for
interpreting
a
JSON-LD
document.
keyword
A
JSON
key
that
is
specific
to
JSON-LD,
specified
in
the
JSON-LD
Syntax
specification
[
JSON-LD
]
in
the
section
titled
Syntax
Tokens
and
Keywords
.
].

3.4
Data
Structures
This
section
describes
datatype
definitions
used
within
the
JSON-LD
API.
3.4.1
URL
The
URL
datatype
is
a
string
representation
of
an
IRI
.
typedef
DOMString
URL
;
This
datatype
indicates
that
the

An
IRI
is
interpreted
as
a
Universal
(Internationalized
Resource
Locator
identifying
a
document,
which
when
parsed
as
JSON
yields
either
a
JSON
object
or
array
.
3.4.2
JsonLdOptions
The
JsonLdOptions
type
Identifier)
is
used
to
convert
a
set
of
options
string
that
conforms
to
an
interface
method.
typedef
the
syntax
defined
in
[
object
RFC3987
JsonLdOptions
;
].

URL
base
The
Base
absolute
IRI
to
use
when
expanding
the
document.
This
overrides
the
value
of
input
if
it
is
a
URL
or
if
it
is
a
object
or
object[]
.
boolean
optimize
If
set
to
true
,
the
JSON-LD
processor
is
allowed
to
optimize
the
output
of
the
Compaction
Algorithm
to
produce
even
compacter
representations.
The
algorithm
for
compaction
optimization
is
beyond
the
scope
of
this
specification
and
thus
not
defined.
Consequently,
different
implementations
may
implement
different
optimization
algorithms.
boolean
noType

If
set
to
true
,
the
JSON-LD
processor
will
not
use
the
@type
property
when
generating
the
output,
and
will
use
the
expanded
rdf:type
An
absolute
IRI
as
the
property
instead
of
@type
.
The
following
data
structures
are
used
for
representing
data
about
RDF
quads.
They
are
used
for
normalization,
fromRDF
,
and
from
toRDF
interfaces.
3.4.3
Quad
The
Quad
interface
represents
an
RDF
Quad.
See
is
defined
in
[
RDF-CONCEPTS
RFC3987
]
definition
for
RDF
triple
,
which
most
closely
aligns
to
Quad
.
]
interface {
};
3.4.3.1
Attributes
graphName
of
type
Node
,
readonly,
nullable
If
present,
the
name
associated
with
the
Quad
identifying
it
as
a
member
of
containing
a
named
graph
.
If
it
is
missing,
the
quad
is
scheme
along
with
a
member
of
the
default
graph
.
Issue
4
This
element
is
at
risk,
path
and
may
be
removed.
object
of
type
Node
,
readonly
The
object
associated
with
the
Quad
.
optional
query
and
fragment
segments.

predicate
of
type
Node
,
readonly
The
predicate
associated
with
the
Quad
relative
IRI
.
Within
JSON-LD,
an
RDF
predicate
is
refered
to
as
a
property
subject
of
type
Node
,
readonly

The
subject
associated
with
the
Quad
.
3.4.4
Node
Node
is
the
base
class
of
A
relative
IRI
,
BlankNode
,
and
Literal
.
It
is
the
IDL
representation
of
a
linked
data
graph
node
.
]
interface {
};
3.4.5
an
IRI
A
node
that
is
an
relative
some
other
absolute
IRI
.
]
interface {
};
3.4.5.1
Attributes
value
of
type
DOMString
,
readonly
The
IRI
identifier
;
in
the
case
of
JSON-LD
this
is
the
node
as
a
[
UNICODE
]
string.
base
location
of
the
document.

3.4.6
Blank
Node
blank
node

A
node
in
the
linked
data
a
JSON-LD
graph
that
does
not
contain
a
de-reference-able
identifier
because
it
is
either
ephemeral
in
nature
or
does
not
contain
information
that
needs
to
be
linked
to
from
outside
of
the
linked
data
graph
.
A
blank
node
is
assigned
an
identifier
starting
with
the
prefix
_:
and
neither
an
implementation
dependent,
auto-generated
suffix
that
is
unique
to
all
information
associated
with
the
particular
blank
node.
]
interface {
};
3.4.6.1
Attributes
IRI
,
nor
a
JSON-LD
value
,
nor
a
list
.

blank
node
identifier
of
type
DOMString
,
readonly

The
temporary
identifier
of
the
A
blank
node
.
The
identifier
must
not
be
relied
upon
in
any
way
between
two
separate
processing
runs
of
the
same
document
or
with
is
a
different
document.
Note
Developers
and
authors
must
not
assume
string
that
the
value
of
can
be
used
as
an
identifier
for
a
blank
node
will
remain
the
same
between
two
processing
runs.
BlankNode
values
are
only
valid
for
the
most
recent
processing
run
on
within
the
scope
of
a
JSON-LD
document.
Blank
node
identifiers
begin
with
BlankNode
values
will
often
be
generated
differently
by
different
processors.
Note
Implementers
must
ensure
that
_:
.

A
Literal
typed
value
is
comprised
consists
of
three
attributes:
a
lexical
form
of
the
value
an
optional
language
tag
value,
which
is
a
datatype
specified
by
string,
and
a
type,
which
is
an
IRI
.

language-tagged
string
Literals
representing
plain
text
in

A
language-tagged
string
consists
of
a
natural
language
may
have
string
and
a
non-empty
language
tag
specified
by
a
string
token,
as
specified
in
defined
by
[
BCP47
],
normalized
to
lowercase
(e.g.,
'en'
,
'fr'
,
'en-gb'
).
They
also
have
a
datatype
attribute
such
as
xsd:string
.
If
unspecified,
the
datatype
defaults
].
The
language
tag
must
be
well-formed
according
to
xsd:string
.
Literals
representing
values
with
a
specific
datatype,
such
as
the
integer
72,
may
have
a
datatype
attribute
specified
in
the
form
of
a
IRI
(e.g.,
xsd:integer
).
See[
RDF-CONCEPTS
]
definition
for
literal
.
]
interface {
};
3.4.7.1
Attributes
datatype
section
2.2.9
Classes
of
type
IRI
Conformance
,
readonly,
nullable
An
optional
datatype
identified
by
a
IRI
.
language
of
type
DOMString
,
readonly,
nullable
An
optional
language
tag
as
defined
in
[
BCP47
],
and
is
normalized
to
lowercase.

4.
Algorithms
All
algorithms
described
in
this
section
are
intended
to
operate
on
language-native
data
structures.
That
is,
the
serialization
to
a
text-based
JSON
document
isn't
required
as
input
or
output
to
any
of
these
algorithms
and
language-native
data
structures
must
be
used
where
applicable.
4.1
5.
Algorithm
Terms

initial
context
active
graph

a
context
that
is
specified
to
the
algorithm
before
processing
begins.
The
contents
name
of
the
initial
context
is
defined
in
Appendix
A
.
active
subject
the
currently
active
subject
graph
that
the
processor
should
use
when
processing.

active
property
subject

the
The
currently
active
property
subject
that
the
processor
should
use
when
processing.
The
active
property
is
represented
in
the
original
lexical
form,
which
is
used
for
finding
coercion
mappings
in
the
active
context
.

active
object
property

the
The
currently
active
object
property
or
keyword
that
the
processor
should
use
when
processing.

active
context

a
A
context
that
is
used
to
resolve
term
terms
s
while
the
processing
algorithm
is
running.
The
active

local
context
is
the

A
context
contained
that
is
specified
within
a
JSON
object
,
specified
via
the
processor
state
@context
keyword
.

JSON-LD
input

The
JSON-LD
data
structure
that
is
provided
as
input
to
the
algorithm.

term

A
term
is
a
short
word
defined
in
a
context
that
may
be
expanded
to
an
IRI

compact
IRI

a
A
compact
IRI
is
has
the
form
of
prefix
and
:
suffix
and
is
used
as
a
way
of
expressing
an
IRI
without
needing
to
define
separate
term
definitions
for
each
IRI
contained
within
a
common
vocabulary
identified
by
prefix
.

it
is
not
the
top-most
JSON
object
,
specified
via
in
the
JSON-LD
document
consisting
of
no
other
members
than
@context
@graph
keyword
.
and
@context
.

processor
state
value
object

the
processor
state
,
which
includes
the
active
context
,
active
subject
,
and
active
property
.
The
processor
state
A
value
object
is
managed
as
a
stack
with
elements
from
the
previous
processor
state
copied
into
a
new
processor
state
when
entering
a
new
JSON
object
.
that
has
an
@value
member.

A
prefix
is
a
term
subject
that
expands
to
a
vocabulary
base
IRI
.
It
is
typically
used
along
with
a
suffix
to
form
a
compact
IRI
as
specified
by
[
RDF11-CONCEPTS
to
create
an
IRI
within
a
vocabulary.
].

language-tagged
literal
RDF
predicate

A
language-tagged
literal
is
a
literal
predicate
without
a
datatype,
including
a
language.
See
as
specified
by
[
literal
RDF11-CONCEPTS
in
].

4.2
6.
Context
Processing
Algorithms

6.1
Context
Processing
Algorithm

Processing
of
When
processing
a
JSON-LD
data
structure
is
managed
recursively.
During
processing,
structure,
each
processing
rule
is
applied
using
information
provided
by
the
active
context
.
Processing
begins
by
pushing
a
new
processor
state
This
section
describes
how
to
produce
an
active
context
.

The
active
context
onto
contains
the
processor
state
active
term
definitions
which
specify
how
properties
and
values
have
to
be
interpreted
as
well
as
the
current
base
IRI
,
the
vocabulary
mapping
and
the
default
language
.
Each
term
definition
stack
consists
of
an
IRI
mapping
,
a
boolean
flag
reverse
property
,
an
optional
type
mapping
or
language
mapping
,
and
initializing
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
referred
to
as
a
keyword
alias
.

If
context
is
also
used
to
maintain
coercion
mapping
s
from
terms
to
datatypes,
language
mapping
s
from
terms
a
string
,
it
represents
a
reference
to
language
codes,
and
list
mapping
s
a
remote
context.
We
dereference
the
remote
context
and
set
mapping
s
for
terms.
Processors
must
use
replace
context
with
the
lexical
form
value
of
the
property
when
creating
a
mapping,
as
lookup
@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
performed
on
lexical
forms,
not
expanded
IRI
representations.
no
cyclical
reference.

Dereference
context
.
If
the
resulting
dereferenced
document
is
a
JSON
document,
extract
the
has
no
top-level
JSON
object
with
an
@context
element
using
the
JSON
Pointer
"/@context"
as
described
in
[
member,
an
JSON-POINTER
invalid
remote
context
].
has
been
detected
and
processing
is
aborted;
otherwise,
set
context
to
the
value
of
that
member.

Set
context
to
the
extracted
content
result
of
recursively
calling
this
algorithm,
passing
context
no
base
for
active
context
,
context
for
local
context
,
and
process
it
by
starting
at
Step
2.1
.
remote
contexts
.

Support
for
the
local
context
.
Otherwise,
@base
keyword
might
be
removed
from
JSON-LD
1.0
if
implementation
experience
reveals
that
the
fact
that
a
document
may
have
multiple
base
IRIs
is
confusing
for
each
property
in
context
perform
developers.
It
is
also
being
discussed
whether
relative
IRIs
are
allowed
as
values
of
@base
or
whether
the
following
steps:
empty
string
should
be
used
to
explicitly
specify
that
there
isn't
a
base
IRI
,
which
could
be
used
to
ensure
that
relative
IRIs
remain
relative
when
expanding.

Algorithm

If
defined
contains
the
property
key
term
and
the
associated
value
is
true
(indicating
that
the
term
definition
has
already
been
created),
return.
Otherwise,
if
the
form
of
of
value
is
false
,
a
compact
cyclic
IRI
mapping
error
has
been
detected
and
processing
is
aborted.

Set
the
value
associated
with
defined
's
term
key
to
false
.
This
indicates
that
the
term
definition
or
absolute
IRI
is
now
being
created
but
is
not
yet
complete.

Set
the
local
context
coercion
type
mapping
using
the
lexical
value
of
the
property
.
definition
to
@id
.

If
the
value
has
a
contains
an
@container
property,
its
value
must
be
member,
set
the
container
mapping
of
definition
to
@list
@index
or
@set
.
Merge
if
that
is
the
list
mapping
value
of
the
@container
member;
otherwise
an
invalid
reverse
property
or
set
mapping
error
has
been
detected
(reverse
properties
only
support
index-containers)
and
processing
is
aborted.

Initialize
type
to
dependencies
in
resolving
term
definitions.
By
continuing
Step
2.3.2
the
value
associated
with
the
@type
key,
which
must
be
a
string
.
Otherwise,
an
invalid
type
mapping
until
no
changes
are
made,
mappings
error
has
been
detected
and
processing
is
aborted.

Initialize
container
to
the
value
associated
with
the
@container
key,
which
must
be
either
@list
,
@set
,
@index
,
or
@language
.
Otherwise,
an
Issue
6
invalid
container
mapping
error
has
been
detected
and
processing
is
aborted.

If
value
contains
the
key
@language
and
does
not
contain
the
key
@type
:

Initialize
language
to
the
value
associated
with
the
@language
key,
which
must
be
either
null
or
a
string
.
Otherwise,
an
invalid
language
mapping
Issue
43
error
has
been
detected
and
processing
is
aborted.

If
language
is
a
string
concerns
performing
IRI
expansion
in
set
it
to
lowercased
language
.
Set
the
key
position
language
mapping
of
a
definition
to
language
.

Otherwise,
if
document
relative
is
true
,
set
value
to
the
result
of
resolving
value
against
the
base
IRI
.
Only
the
basic
algorithm
in
section
5.2
of
[
RFC3986
]),
generate
an
]
is
used;
neither
Syntax-Based
Normalization
nor
Scheme-Based
Normalization
are
performed.
Characters
additionally
allowed
in
IRI
by
prepending
the
mapped
prefix
to
references
are
treated
in
the
(possibly
empty)
suffix
using
textual
concatenation.
Note
same
way
that
an
empty
suffix
and
no
suffix
(meaning
the
value
contains
no
':'
string
at
all)
unreserved
characters
are
treated
equivalently.
in
URI
references,
per
section
6.5
of
[
RFC3987
].

Overview

IRI

s.
This
section
defines
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
treat
each
one
differently
according
to
its
type,
in
order
to
break
down
the
problem:

If
expanded
property
is
@set
@graph
,
continue
set
expanded
value
to
the
next
term
.
result
of
using
this
algorithm
recursively
passing
active
context
,
@graph
for
active
property
,
and
value
for
element
.

If
list
container
expanded
property
is
true
@value
and
term
does
value
is
not
have
a
container
scalar
or
null
,
an
invalid
value
object
value
error
has
been
detected
and
processing
is
aborted.
Otherwise,
set
expanded
value
to
value
.
If
expanded
value
is
null
,
set
the
@list
,
continue
@value
member
of
result
to
null
and
continue
with
the
next
term
.
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.

Otherwise,
if
term
has
If
expanded
property
is
@language
and
value
is
not
a
string
,
an
invalid
language-tagged
string
error
has
been
detected
and
processing
is
aborted.
Otherwise,
set
expanded
value
to
lowercased
value
.

If
expanded
property
is
container
@index
and
value
is
not
a
string
,
an
invalid
@index
value
error
has
been
detected
and
processing
is
aborted.
Otherwise,
set
expanded
value
to
value
.

If
expanded
property
is
@list
:

If
active
property
is
null
or
@graph
,
continue
to
with
the
next
term
.
key
from
element
to
remove
the
free-floating
list.

If
rank
expanded
value
is
greater
than
0
:
If
term
has
a
container
list
object
,
a
list
of
lists
set
to
error
has
been
detected
and
processing
is
aborted.

If
expanded
property
is
@set
,
then
add
1
set
expanded
value
to
rank
.
the
result
of
using
this
algorithm
recursively,
passing
active
context
,
active
property
,
and
value
for
element
.

If
expanded
property
is
@reverse
and
value
is
not
a
JSON
object
,
an
invalid
@reverse
value
containing
only
the
property
@list
error
has
been
detected
and
list
container
processing
is
aborted.
Otherwise

Initialize
expanded
value
to
the
result
of
using
this
algorithm
recursively,
passing
active
context
,
false
@reverse
as
active
property
,
and
term
has
a
value
as
element
.

If
expanded
value
contains
an
container
@reverse
member,
i.e.,
properties
that
are
reversed
twice,
execute
for
each
of
its
property
and
item
the
following
steps:

If
result
does
not
have
a
property
member,
create
one
and
set
its
value
to
@list
,
then
set
list
container
an
empty
array
.

Append
item
to
the
value
of
the
property
member
of
result
.

If
expanded
value
contains
members
other
than
true
,
clear
terms
,
set
highest
rank
to
rank
,
@reverse
:

If
result
does
not
have
an
@reverse
member,
create
one
and
add
term
set
its
value
to
terms
.
an
empty
JSON
object
.

Otherwise,
if
rank
is
greater
Reference
the
value
of
the
@reverse
member
in
result
using
the
variable
reverse
map
.

For
each
property
and
items
in
expanded
value
other
than
or
equal
to
highest
rank
:
@reverse
:

Otherwise,
if
key
's
container
mapping
associated
with
the
partially
matched
IRI
in
the
active
context
concatenated
with
a
colon
(:)
character
is
@index
and
the
unmatched
part
of
iri
.
value
is
a
JSON
object
then
value
is
expanded
from
an
index
map
as
follows:

If
the
@list
reverse
map
has
no
expanded
property
is
member,
create
one
and
initialize
its
value
to
an
empty
array,
if
term
has
@container
set
to
@list
,
term
rank
is
1
,
otherwise
0
.
array
.

Otherwise,
return
Append
item
to
the
sum
value
of
the
term
rank
s
for
every
entry
in
the
list.
expanded
property
member
of
reverse
map
.

Otherwise,
value
must
be
a
subject
definition
,
subject
reference
,
or
a
JSON
object
having
if
key
is
not
a
@value
.
reverse
property
:

If
result
does
not
have
an
expanded
property
member,
create
one
and
initialize
its
value
has
a
@value
property:
to
an
empty
array
.

If
Append
expanded
value
has
a
@type
to
value
of
the
expanded
property
matching
a
member
of
result
.

If
result
contains
the
key
@type
coercion
for
term
,
term
rank
is
@value
:

The
result
must
not
contain
any
keys
other
than
3
@value
,
otherwise
if
term
has
no
@type
coercion
and
no
@language
,
term
rank
is
1
@type
,
otherwise
and
0
@index
.
Otherwise,
if
It
must
not
contain
both
the
@value
@language
is
not
a
string
,
if
term
has
no
key
and
the
@type
or
@language
key.
Otherwise,
an
invalid
value
object
it
error
has
been
detected
and
processing
is
2
,
otherwise
1
.
aborted.

Otherwise,
if
If
the
value
has
no
@language
property,
if
term
has
of
result
's
@language
@value
key
is
null
,
or
term
has
no
@type
or
then
set
result
to
null
.

Otherwise,
if
the
value
of
result
's
@language
@value
member
is
not
a
string
and
result
contains
the
active
context
has
no
key
@language
,
term
rank
an
invalid
language-tagged
value
error
has
been
detected
(only
strings
can
be
language-tagged)
and
processing
is
3
,
otherwise
0
.
aborted.

Otherwise,
if
value
the
result
has
a
@language
@type
property
matching
member
and
its
value
is
not
a
@language
string
,
an
invalid
typed
value
definition
for
term
(or
term
error
has
no
been
detected
and
processing
is
aborted.

Otherwise,
if
result
contains
the
key
@type
or
@language
definition
and
@language
in
the
active
context
matches
the
its
associated
value
@language
),
term
rank
is
3
,
otherwise
not
an
array
,
set
it
to
an
array
containing
only
the
associated
value.

Otherwise,
if
term
has
no
result
contains
the
key
@type
@set
coercion
or
@list
:

The
result
must
contain
at
most
one
other
key
and
no
that
key
must
be
@language
,
term
rank
@index
.
Otherwise,
an
invalid
set
or
list
object
error
has
been
detected
and
processing
is
aborted.

If
result
contains
the
key
1
@set
,
otherwise
0
.
then
set
result
to
the
key's
associated
value.

Otherwise,
if
term
has
@type
coerced
to
If
result
contains
only
the
key
@id
@language
,
term
rank
set
result
to
null
.

If
result
is
an
empty
JSON
object
or
contains
the
keys
@type
@value
coercion
and
no
or
@language
@list
,
term
rank
set
result
to
null
.

Otherwise,
if
result
is
a
JSON
object
whose
only
key
is
1
@id
,
otherwise
0
.
set
result
to
null
.

Return
term
rank
.
result
.

If,
after
the
above
algorithm
is
run,
the
result
is
a
JSON
object
that
contains
only
an
@graph
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.

4.5
7.2
Value
Expansion

Some
values
in
JSON-LD
can
be
expressed
in
a
compact
form.
form
.
These
values
are
required
to
be
expanded
at
times
when
processing
JSON-LD
documents.
The
algorithm
for
expanding
a
A
value
takes
an
active
property
and
active
context
.
It
is
implemented
as
follows:
said
to
be
in
expanded
form
after
the
application
of
this
algorithm.

If

Overview

value
This
section
is
null
,
the
value
non-normative.
is
already
expanded.

Otherwise,
the
result
will
be
a
keyword
,
then
expand
value
into
JSON
object
containing
an
object:
Set
the
first
key-value
pair
to
@value
and
the
unexpanded
member
whose
value
.
If
the
active
property
is
the
target
of
typed
literal
coercion,
set
the
second
key-value
pair
to
passed
value
.
Additionally,
an
@type
and
the
associated
coercion
datatype
expanded
according
to
the
IRI
Expansion
rules.
Otherwise,
member
will
be
included
if
there
is
a
type
mapping
associated
with
the
active
property
is
the
target
of
language
tagging,
set
the
second
key-value
pair
to
or
an
@language
and
member
if
value
of
the
is
a
string
and
there
is
language
tagging
from
mapping
associated
with
the
active
context
property
.
Otherwise,
value
is
already
expanded.
4.6
Value
Compaction
Some
values,
such
as
IRIs
and
typed
literals
,
may
be
expressed
in
an
expanded
form
in
JSON-LD.
These
values
are
required
to
be
compacted
at
times
when
processing
JSON-LD
documents.

Algorithm

The
algorithm
for
compacting
an
expanded
value
value
takes
three
required
inputs:
an
active
context
,
an
active
property
,
and
active
context
.
It
is
implemented
as
follows:
a
value
to
expand.

Otherwise,
if
value
contains
initialize
result
to
a
JSON
object
with
an
@id
@value
key,
the
compacted
member
whose
value
is
value
with
the
value
of
@id
processed
according
set
to
the
IRI
Compaction
steps.
value
.

Running
the
JSON-LD
Expansion
algorithm
against
Starting
with
its
root
element
,
we
can
process
the
JSON-LD
input
document
provided
above
would
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
following
output:
problem:

The
final
output
is
a
JSON
object
with
a
@context
key,
if
a
non-empty
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
.

If
property
does
is
not
expand
to
a
keyword
or
member
of
result
,
add
one
and
set
its
value
to
value
.

Otherwise,
if
the
value
of
the
property
member
of
result
is
not
an
absolute
IRI
(i.e.,
array
,
set
it
doesn't
contain
to
a
colon),
continue
with
new
array
containing
only
the
next
value.
Then
append
value
to
its
value
if
value
is
not
an
array
,
otherwise
append
each
of
its
items.

Remove
the
property
member
from
element
.
compacted
value
.

If
compacted
value
is
null
and
property
has
some
remaining
members,
i.e.,
it
is
not
an
empty
JSON
object
:

Set
the
value
of
the
alias
member
of
result
to
compacted
value
and
continue
with
the
next
expanded
property
from
element
.
.

If
the
expanded
property
is
@id
@index
and
active
property
has
a
container
mapping
in
active
context
that
is
@index
,
then
the
value
must
compacted
result
will
be
a
string
.
Expand
inside
of
an
@index
container,
drop
the
value
according
@index
property
by
continuing
to
IRI
Expansion
.
the
next
expanded
property
.

If
result
does
not
have
the
key
that
equals
item
active
property
,
set
this
key's
value
in
result
to
an
empty
array
.
Otherwise,
if
the
key's
value
is
not
an
array
,
all
elements
must
be
either
a
string
or
subject
reference
.
Expand
value
for
each
of
its
entries
using
then
set
it
to
one
containing
only
the
previous
three
steps.
value.

Otherwise,
if
the
property
is
@value
or
@language
the
At
this
point,
expanded
value
must
not
be
a
JSON
object
or
an
array
due
to
the
Expansion
algorithm
.
For
each
item
expanded
item
in
expanded
value
:

Otherwise,
expand
value
recursively
using
this
algorithm,
passing
copies
If
expanded
item
contains
the
key
@index
,
then
add
a
key-value
pair
to
compacted
item
where
the
key
is
the
result
of
the
IRI
Compaction
algorithm
,
passing
active
context
,
inverse
context
,
@index
as
iri
,
and
active
property
.
the
associated
with
the
@index
key
in
expanded
item
as
value
.

If
item
active
property
is
not
null
,
convert
value
a
key
in
result
,
then
initialize
map
object
to
its
associated
value,
otherwise
initialize
it
to
an
empty
JSON
object
with
an
.

If
container
is
@list
@language
property
whose
value
is
and
compacted
item
contains
the
key
@value
,
then
set
compacted
item
to
the
value
(unless
associated
with
its
@value
key.

Initialize
map
key
to
the
value
is
already
in
associated
with
with
the
key
that
form).
equals
container
in
expanded
item
.

Convert
If
map
key
is
not
a
key
in
map
object
,
then
set
this
key's
value
in
map
object
to
compacted
item
.
Otherwise,
if
the
value
is
not
an
array
form
unless
,
then
set
it
to
one
containing
only
the
value
is
null
and
then
append
compacted
item
to
it.

Otherwise,

If
compactArrays
or
property
is
false
,
container
is
@id
,
@set
or
@type
@list
,
or
expanded
property
is
@value
,
@list
or
@language
.
@graph
and
compacted
item
is
not
an
array
,
set
it
to
a
new
array
containing
only
compacted
item
.

If
value
item
active
property
is
not
null
,
either
merge
value
into
an
existing
a
key
in
result
then
add
the
key-value
pair,
(
item
active
property
-
compacted
item
),
to
result
.

Otherwise,
if
the
value
associated
with
the
key
that
equals
item
active
property
of
element
or
create
in
result
is
not
an
array
,
set
it
to
a
new
property
property
with
value
as
array
containing
only
the
value.
Then
append
compacted
item
to
the
value
if
compacted
item
is
not
an
array
,
otherwise,
concatenate
it.

If
Return
result
.

If,
after
the
processed
element
algorithm
outlined
above
is
run,
the
result
result
is
an
array
,
replace
it
with
a
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
array
result
.
Finally,
if
a
non-empty
context
has
been
passed,
add
an
@value
@context
property
member
to
result
and
set
its
value
to
the
passed
context
.

element
must
not
have
8.2
Inverse
Context
Creation

When
there
is
more
than
one
other
property,
which
can
either
term
that
could
be
@language
or
@type
with
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.

If
iri
is
not
a
key
in
result
,
add
a
key-value
pair
where
the
form
of
key
is
iri
and
the
value
is
an
array
,
convert
it
empty
JSON
object
to
an
array
.
result
.

Reference
the
value
associated
with
the
iri
member
in
result
using
the
variable
container
map
.

If
element
container
has
an
no
container
map
member,
create
one
and
set
its
value
to
a
new
JSON
object
with
two
members.
The
first
member
is
@set
@language
or
and
its
value
is
a
new
empty
JSON
object
,
the
second
member
is
@list
@type
property,
it
must
be
and
its
value
is
a
new
empty
JSON
object
.

Reference
the
only
property.
Set
element
to
value
associated
with
the
container
member
in
container
map
using
the
variable
type/language
map
.

Reference
the
value
associated
with
the
@type
member
in
type/language
map
using
the
variable
type
map
.

If
type
map
does
not
have
a
member
corresponding
to
the
Value
Expansion
type
mapping
rules,
passing
copies
of
in
term
definition
,
create
one
and
set
its
value
to
the
active
context
term
and
active
property
.
being
processed.

If
language
map
does
not
have
a
language
member,
create
one
and
set
its
value
to
the
term
being
processed.

Otherwise:

Reference
the
value
associated
with
just
the
@language
member
in
type/language
map
using
the
variable
language
map
.

If
language
map
does
not
have
a
default
language
member,
create
one
and
set
its
value
to
the
term
being
processed.

If
language
map
does
not
have
a
@graph
@none
property,
element
is
member,
create
one
and
set
its
value
to
the
term
being
processed.

Reference
the
value
of
associated
with
the
@graph
@type
's
value.
Finally,
if
element
is
member
in
type/language
map
using
the
variable
type
map
.

If
type
map
does
not
have
a
JSON
object
,
it
is
wrapped
into
an
array
.
@none
member,
create
one
and
set
its
value
to
the
term
being
processed.

Return
result
.

4.8
8.3
IRI
Compaction

Compaction
is
the
process
of
taking
a
JSON-LD
document
and
applying
This
algorithm
compacts
an
IRI
to
a
context
such
that
the
most
term
or
compact
form
of
the
document
is
generated.
JSON
is
typically
expressed
in
IRI
,
or
a
very
compact,
key-value
format.
That
is,
full
IRIs
are
rarely
used
as
keys.
At
times,
keyword
to
a
JSON-LD
document
may
be
received
keyword
alias
.
A
value
that
is
not
in
its
most
compact
form.
JSON-LD,
via
associated
with
the
API,
provides
a
way
IRI
may
be
passed
in
order
to
compact
a
JSON-LD
document.
For
example,
assume
assist
in
selecting
the
following
JSON-LD
input
document:
most
context-appropriate
term
.

Running
If
the
JSON-LD
Compaction
algorithm
given
passed
IRI
is
null
,
we
simply
return
null
.
Otherwise,
we
first
try
to
find
a
term
that
the
context
supplied
above
against
IRI
or
keyword
can
be
compacted
to
if
it
is
relative
to
active
context's
vocabulary
mapping
.
In
order
to
select
the
JSON-LD
input
document
provided
above
most
appropriate
term
,
we
may
have
to
collect
information
about
the
passed
value
.
This
information
includes
which
container
mappings
would
result
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
following
output:
{
"@context": {
"name": "http://xmlns.com/foaf/0.1/name",
"homepage": {
"@id": "http://xmlns.com/foaf/0.1/homepage",
"@type": "@id"
}
},
"name": "Manu Sporny",
"homepage": "http://manu.sporny.org/"
}
The
compaction
list.
Once
this
information
is
gathered,
it
is
passed
to
the
Term
Selection
algorithm
also
enables
,
which
will
return
the
developer
most
appropriate
term
to
map
any
expanded
format
into
use.

Algorithm

The
This
algorithm
takes
three
input
variables:
required
inputs
and
three
optional
inputs.
The
required
inputs
an
active
context
,
an
active
property
inverse
context
,
and
an
element
the
iri
to
be
compacted.
To
begin,
the
active
context
is
set
to
The
optional
inputs
are
a
value
associated
with
the
result
of
performing
Context
Processing
on
iri
,
a
vocab
flag
which
specifies
whether
the
passed
context
,
iri
should
be
compacted
using
the
active
context's
vocabulary
mapping
,
and
a
reverse
flag
which
specifies
whether
a
reverse
property
is
being
compacted.
If
not
passed,
value
is
set
to
null
,
and
element
is
vocab
and
reverse
are
both
set
to
the
result
of
performing
the
Expansion
Algorithm
on
the
JSON-LD
input
false
.

Initialize
type/language
to
@language
,
and
type/language
value
to
@null
.
These
two
variables
will
keep
track
of
the
active
property
.
If
element
has
preferred
type
mapping
or
language
mapping
for
a
single
item,
the
compacted
term
,
based
on
what
is
compatible
with
value
.

If
value
is
a
JSON
object
that
item;
otherwise
contains
the
key
@index
,
then
append
the
compacted
value
@index
to
containers
.

If
reverse
is
element
.
true
,
set
type/language
to
@type
,
type/language
value
to
@reverse
,
and
append
@set
to
containers
.

Otherwise,
if
element
value
is
an
object:
a
list
object
,
then
set
type/language
and
type/language
value
to
the
most
specific
values
that
work
for
all
items
in
the
list
as
follows:

If
element
has
an
@value
@index
property
or
element
is
a
subject
reference
,
return
not
key
in
value
,
then
append
@list
to
containers
.

Initialize
list
to
the
result
of
performing
Value
Compaction
array
on
element
using
active
property
associated
with
the
key
@list
in
value
.

Initialize
common
language
to
null
.
If
list
is
empty,
set
common
language
to
default
language
.

For
each
item
in
list
:

Initialize
item
language
to
@none
and
item
type
to
@none
.

If
item
contains
the
key
@value
:

If
item
contains
the
key
@language
,
then
set
item
language
to
its
associated
value.

Otherwise,
if
item
contains
the
active
property
has
a
key
@container
@type
,
set
item
type
to
its
associated
value.

Otherwise,
if
item
type
does
not
equal
common
type
,
then
set
common
type
to
@list
@none
because
list
items
have
conflicting
types.

If
common
language
is
@none
and
element
common
type
is
@none
,
then
stop
processing
items
in
the
list
because
it
has
a
corresponding
been
detected
that
there
is
no
common
language
or
type
amongst
the
items.

If
value
contains
the
active
context
key
@language
and
does
not
contain
the
active
property
key
@index
,
then
set
type/language
value
to
its
associated
value
and
append
@language
to
containers
.

Otherwise,
if
value
contains
the
key
@type
,
then
set
type/language
value
to
its
associated
value
and
set
type/language
to
@type
.

Otherwise,
set
type/language
to
@type
and
set
type/language
value
to
@id
.

Append
@set
to
containers
.

Append
@none
to
containers
.
This
represents
the
non-existence
of
a
container
mapping
,
and
it
will
be
the
last
container
mapping
ensuring
that
value
to
be
checked
as
it
is
the
result
most
generic.

If
type/language
value
is
an
array
and
removing
null
values.
Return
either
,
set
it
to
@null
.
This
is
the
result
as
an
array,
as
an
object
with
a
key
of
@list
(or
appropriate
alias
from
active
under
which
null
values
are
stored
in
the
inverse
context
).
entry
.

Otherwise,
construct
output
as
a
new
JSON
object
Initialize
preferred
values
to
an
empty
array
.
This
array
used
for
returning
will
indicate,
in
order,
the
result
of
compacting
element
.
For
each
property
and
preferred
values
for
a
term's
type
mapping
or
language
mapping
.

Otherwise,
return
element
as
if
value
has
an
@type
member
whose
value
matches
the
compacted
element
.
Issue
7
Perhaps
this
should
also
call
Value
Compaction
type
mapping
on
native
types
and
strings,
which
could
consolidate
potential
transformation
in
one
place.
If,
after
of
active
property
,
return
the
algorithm
outlined
above
is
run,
value
associated
with
the
resulting
element
is
@value
member
of
value
.

Otherwise,
if
value
has
an
array
@language
member
whose
value
matches
the
language
mapping
of
active
property
,
put
element
into
return
the
value
associated
with
the
@graph
@value
property
member
of
a
new
JSON
object
value
.

9.
Flattening
Algorithms

4.9
9.1
RDF
Conversion
Flattening
Algorithm

A
This
algorithm
flattens
an
expanded
JSON-LD
document
may
be
converted
between
other
RDF-compatible
document
formats
using
the
algorithms
specified
in
this
section.
The
JSON-LD
Processing
Model
describes
processing
rules
for
extracting
RDF
from
a
JSON-LD
document,
and
for
transforming
an
array
of
Quad
retrieved
by
processing
another
serialization
format
into
JSON-LD.
Note
that
many
uses
of
JSON-LD
may
not
require
generation
collecting
all
properties
of
RDF.
The
processing
algorithms
described
in
this
section
are
provided
a
node
in
order
to
demonstrate
how
one
might
implement
a
JSON-LD
to
RDF
processor.
Conformant
implementations
are
only
required
to
produce
the
same
type
single
JSON
object
and
number
labeling
all
blank
nodes
with
blank
node
identifiers
.
This
resulting
uniform
shape
of
quads
during
the
output
process
and
are
not
document,
may
drastically
simplify
the
code
required
to
implement
the
algorithm
exactly
as
described.
process
JSON-LD
data
in
certain
applications.

Algorithm

As
with
other
grammars
The
algorithm
takes
two
input
variables,
an
element
to
flatten
and
an
optional
context
used
for
describing
Linked
Data
,
to
compact
the
flattened
document.
If
not
passed,
context
is
set
to
null
.

Initialize
node
map
to
a
JSON
object
consisting
of
a
single
member
whose
key
concept
is
that
@default
and
whose
value
is
an
empty
JSON
object
.

For
each
key-value
pair
graph
name
-
graph
in
node
map
where
graph
name
is
not
@default
,
perform
the
following
steps:

If
default
graph
does
not
have
a
linked
data
graph
.
Nodes
may
be
name
member,
create
one
and
initialize
its
value
to
a
JSON
object
consisting
of
three
basic
types.
The
first
an
@id
member
whose
value
is
set
to
graph
name
.

Reference
the
value
associated
with
the
graph
name
member
in
default
graph
using
the
variable
entry
.

Add
an
IRI
@graph
,
which
is
used
member
to
refer
entry
and
set
it
to
an
empty
array
.

For
each
id
-
node
s
pair
in
other
linked
data
graph
s.
The
second
is
ordered
by
id
,
add
node
to
the
blank
@graph
member
of
entry
.

If
context
is
null
,
which
are
nodes
for
which
an
external
name
does
not
exist,
or
return
flattened
.

Otherwise,
return
the
result
of
compacting
flattened
according
the
Compaction
algorithm
passing
context
ensuring
that
the
compaction
result
uses
the
@graph
keyword
(or
its
alias)
at
the
top-level,
even
if
the
context
is
not
known.
The
third
empty
or
if
there
is
only
one
element
to
put
in
the
@graph
array
.
This
ensures
that
the
returned
document
has
a
Literal
,
which
express
values
such
as
strings,
dates
and
other
information
having
a
lexical
form,
possibly
including
an
explicit
language
or
datatype.
deterministic
structure.

9.2
Node
Map
Generation

Data
described
with
JSON-LD
may
be
considered
to
be
This
algorithm
creates
a
graph
made
up
JSON
object
node
map
holding
an
indexed
representation
of
subject
the
graphs
and
object
nodes
represented
in
the
passed
expanded
document.
All
nodes
related
via
that
are
not
uniquely
identified
by
an
IRI
get
assigned
a
property
(new)
blank
node
identifier
.
Specific
implementations
may
also
choose
to
operate
on
The
resulting
node
map
will
have
a
member
for
every
graph
in
the
document
as
whose
value
is
another
object
with
a
normal
JSON
description
of
objects
having
attributes.
Both
approaches
member
for
every
node
represented
in
the
document.
The
default
graph
is
stored
under
the
@default
member,
all
other
graphs
are
valid
ways
to
interact
with
JSON-LD
documents.
stored
under
their
graph
name
.

4.9.2
Parsing
Examples

Overview

This
section
is
non-normative.

The
following
examples
show
simple
transformations
of
algorithm
recursively
runs
over
an
expanded
JSON-LD
documents
to
Turtle
[
TURTLE-TR
].
The
first
example
uses
a
simple
document
containing
a
simple
FOAF
profile:
{
"@context": {"foaf": "http://xmlns.com/foaf/0.1/"},
"@id": "http://greggkellogg.net/foaf#me",
"@type": "foaf:Person",
"foaf:name": "Gregg Kellogg",
"foaf:knows": {
"@type": "foaf:Person",
"foaf:name": "Manu Sporny"
}
}
This
translates
fairly
directly
to
collect
all
properties
of
a
similar
Turtle
document:
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
<http://greggkellogg.net/foaf#me> a foaf:Person;
foaf:name "Gregg Kellogg";
foaf:knows
[
node
in
a
foaf:Person;
foaf:name
"Manu
Sporny"].
single
JSON
object
.
The
actual
parsing
steps
first
require
that
algorithm
constructs
a
JSON
object
node
map
whose
keys
represent
the
graph
names
used
in
the
JSON-LD
document
be
expanded,
to
eliminate
(the
default
graph
is
stored
under
the
key
@context
:
[{
"@id": "http://greggkellogg.net/foaf#me",
"@type": ["http://xmlns.com/foaf/0.1/Person"],
"http://xmlns.com/foaf/0.1/name": [{"@value": "Gregg Kellogg"}],
"http://xmlns.com/foaf/0.1/knows": [{
"@type": ["http://xmlns.com/foaf/0.1/Person"],
"http://xmlns.com/foaf/0.1/name": [{"@value": "Manu Sporny"}]
}]
}]
The
process
of
translating
this
to
RDF
then
operates
over
each
subject
definition
@default
)
and
whose
associated
values
are
JSON
objects
to
find
which
index
the
nodes
in
the
graph
.
If
a
subject,
each
property
property's
to
find
an
RDF
predicate
,
and
each
value
is
a
node
object
,
it
is
replace
by
a
node
object
consisting
of
that
property
to
find
only
an
@id
member.
If
a
node
object
.
In
this
case,
each
property
has
just
a
single
object:
no
foaf:name
@id
identifies
member
or
it
is
identified
by
a
literal
blank
node
identifier
,
and
foaf:knows
identifies
a
second
subject
definition
new
blank
node
identifier
similar
to
Turtle's
blankNodePropertyList
.
After
expansion,
JSON-LD
numbers
,
booleans
,
typed-
and
language-tagged-
literals
,
and
IRIs
is
generated.
This
relabeling
of
blank
node
identifiers
become
explicit,
and
can
is
also
be
directly
transformed
into
their
RDF
representations.
[{
"@id": "http://greggkellogg.net/foaf#me",
"@type": ["http://xmlns.com/foaf/0.1/Person"],
"http://xmlns.com/foaf/0.1/name": [{"@value": "Gregg Kellogg"}],
"http://xmlns.com/foaf/0.1/currentProject": [{"@id": "http://json-ld.org/"}],
"http://xmlns.com/foaf/0.1/birthday": [{
"@value": "1957-02-27",
"@type": "http://www.w3.org/2001/XMLSchema#date"
}],
"http://xmlns.com/foaf/0.1/knows": [{
"@type": ["http://xmlns.com/foaf/0.1/Person"],
"http://xmlns.com/foaf/0.1/name": [{"@value": "Manu Sporny"}]
}]
}]
Translates
to:
done
for
properties
and
values
of
@type
.

Algorithm

The
algorithm
below
is
designed
for
in-memory
implementations
with
random
access
takes
as
input
an
expanded
JSON-LD
document
element
and
a
reference
to
a
JSON
object
elements.
A
conforming
JSON-LD
processor
implementing
RDF
conversion
must
implement
a
processing
algorithm
that
results
in
node
map
.
Furthermore
it
has
the
same
set
of
RDF
Quads
optional
parameters
active
graph
that
the
following
algorithm
generates:
The
algorithm
takes
five
input
variables:
a
element
(which
defaults
to
be
converted,
@default
),
an
active
subject
,
active
property
,
and
graph
name
.
To
begin,
the
a
reference
to
a
JSON
object
list
.
If
not
passed,
active
subject
,
active
property
,
and
graph
name
list
are
set
to
null
.

If
element
is
an
array,
process
each
item
in
element
as
follows
and
then
return:

Otherwise
element
is
set
to
a
JSON
object
.
Reference
the
result
JSON
object
which
is
the
value
of
performing
the
Expansion
Algorithm
active
graph
on
member
of
node
map
using
the
JSON-LD
input
.
This
removes
any
existing
context
to
allow
variable
graph
.
If
the
given
context
active
subject
is
null
,
set
node
to
be
cleanly
applied.
null
otherwise
reference
the
active
subject
member
of
graph
using
the
variable
node
.

If
element
is
a
JSON
object
,
has
an
@type
member,
perform
for
each
item
the
following
steps:

Otherwise,
compare
element
against
every
item
in
the
array
associated
with
the
active
property
member
of
@value
node
.
If
there
is
a
number
,
set
no
item
equivalent
to
element
,
append
element
to
the
active
object
array
.
Two
JSON
objects
are
considered
equal
if
they
have
equivalent
key-value
pairs.

Otherwise,
append
element
to
the
@list
member
of
list
.

Otherwise,
if
element
has
an
@list
member,
perform
the
following
steps:

Initialize
a
typed
literal
new
JSON
object
using
a
string
representation
result
consisting
of
the
a
single
member
@list
whose
value
as
defined
in
the
section
Data
Round
Tripping
.
Set
datatype
is
initialized
to
an
empty
array
.

If
node
does
not
have
an
active
property
created
from
member,
create
one
and
initialize
its
value
to
an
array
containing
reference
.

Otherwise,
compare
reference
against
every
item
in
the
string
representation
array
associated
with
the
active
property
member
of
node
.
If
there
is
no
item
equivalent
to
reference
,
append
reference
to
the
value.
Set
datatype
array
.
Two
JSON
objects
are
considered
equal
if
they
have
equivalent
key-value
pairs.

Otherwise,
append
element
to
the
@list
member
of
list
.

Reference
the
value
of
the
id
member
of
graph
using
the
variable
node
.

If
element
has
an
@type
property
if
key,
append
each
item
of
its
associated
array
to
the
array
associated
with
the
@type
key
of
node
unless
it
exists,
otherwise
is
already
in
that
array
.
Finally
remove
the
xsd:boolean
.
@type
member
from
element
.

Otherwise,
if
If
element
contains
a
has
an
@type
@index
property,
member,
set
the
active
object
@index
member
of
node
to
its
value.
If
node
has
already
an
@index
member
with
a
typed
literal
.
different
value,
a
conflicting
indexes
error
has
been
detected
and
processing
is
aborted.
Otherwise,
continue
by
removing
the
@index
member
from
element
.

Otherwise,
if
If
element
contains
a
has
an
@language
@reverse
property,
set
the
active
member:

Create
a
JSON
object
to
referenced
node
with
a
language-tagged
literal
.
single
member
@id
whose
value
is
id
.

Otherwise,
set
Set
reverse
map
to
the
active
object
value
of
the
@reverse
member
of
element
.

For
each
key-value
pair
property
-
values
in
reverse
map
:

For
each
value
of
values
:

If
value
has
a
property
member,
append
referenced
node
to
its
value;
otherwise
create
a
typed
literal
property
member
whose
value
is
an
array
using
containing
referenced
node
.

If
element
has
a
an
@list
@graph
member,
recursively
invoke
this
algorithm
passing
the
value
of
the
@graph
member
for
element
,
node
map
,
and
id
for
active
graph
before
removing
the
@graph
member
from
element
.

Finally,
for
each
key-value
pair
property
-
value
in
element
ordered
by
property
perform
the
following
steps:

9.3
Generate
Blank
Node
Identifier

Overview

This
section
is
non-normative.

The
simplest
case
is
if
there
exists
already
a
blank
node
identifier
in
the
active
object
identifier
map
for
the
passed
identifier
,
in
which
case
it
is
simply
returned.
Otherwise,
a
new
blank
node
identifier
is
generated
by
concatenating
the
string
_:b
and
the
counter
.
If
active
object
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
and
the
new
blank
node
identifier
is
returned.

Algorithm

The
algorithm
takes
a
single
input
variable
identifier
which
may
be
null
.
Between
its
executions,
the
algorithm
needs
to
keep
an
identifier
map
to
relabel
existing
blank
node
identifiers
consistently
and
a
counter
to
generate
new
blank
node
identifiers
.
The
counter
is
initialized
to
0
by
default.

If
neither
active
subject
nor
active
property
are
identifier
is
not
null
,
and
has
an
entry
in
the
identifier
map
,
return
the
mapped
identifier.

10.
RDF
Conversion
Algorithms

This
section
describes
algorithms
to
transform
a
@id
property,
JSON-LD
document
to
an
RDF
dataset
and
vice
versa.
The
algorithms
are
designed
for
in-memory
implementations
with
random
access
to
JSON
object
elements.

If
property
is
@type
,
set
the
active
property
then
for
each
type
in
values
,
append
a
triple
to
composed
of
subject
,
rdf:type
.
Otherwise,
if
property
is
@graph
,
process
value
algorithm
recursively,
using
active
subject
as
graph
name
and
null
values
for
active
subject
and
active
property
and
then
proceed
type
to
next
property.
triples
.

If
item
is
a
list
object
,
initialize
list
triples
as
an
empty
array
and
list
head
to
the
result
of
the
List
Conversion
algorithm
,
passing
the
value
associated
with
the
@list
key
from
item
and
list
triples
.
Append
first
a
triple
composed
of
subject
,
property
.
,
and
list
head
to
triples
and
finally
append
all
triples
from
list
triples
to
triples
.

Otherwise,
if
datatype
is
null
,
active
object
set
it
to
xsd:string
or
rdf:langString
,
depending
on
if
item
has
an
@language
member.

Initialize
literal
as
an
RDF
literal
using
value
and
graph
name
.
datatype
.
If
item
has
an
@language
member,
add
the
value
associated
with
the
@language
key
as
the
language
tag
of
literal
.

Return
active
object
.
literal
.

4.9.4
10.3
List
to
RDF
Conversion

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
].

Algorithm

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.
generated
triples
.

For
each
element
in
array
other
than
the
last
element:
pair
of
subject
from
bnodes
and
item
from
list
:

Create
Append
a
processor
state
using
first
blank
node
as
the
active
triple
composed
of
subject
,
and
,
rdf:first
as
the
active
property
.
Process
,
and
the
value
starting
at
Step
1
.
Proceed
result
of
using
the
previous
processor
state
.
th
Object
to
RDF
Conversion
algorithm
passing
item
to
list
triples
.

Unless
this
is
Set
rest
as
the
last
element
next
entry
in
array
,
generate
a
new
blank
node
identified
as
rest
blank
node
,
otherwise
use
bnodes
,
or
if
that
does
not
exist,
rdf:nil
.
Generate
Append
a
new
Quad
triple
using
first
blank
node
,
composed
of
subject
,
rdf:rest
,
and
rest
blank
node
.
Set
first
blank
node
to
rest
blank
node
.
list
triples
.

Return
the
first
blank
node
.
from
bnodes
or
rdf:nil
if
bnodes
is
empty.

4.9.5
10.4
Convert
from
RDF
Algorithm

In
some
cases,
data
exists
natively
in
Triples
or
Quads
form;
for
example,
if
the
data
was
originally
represented
in
an
RDF
graph
or
triple/quad
store.
This
algorithm
is
designed
to
simply
translate
converts
an
array
RDF
dataset
consisting
of
Quads
a
default
graph
and
zero
or
more
named
graphs
into
a
JSON-LD
document.

In
the
interest
of
xsd:string
,
space
and
simplicity,
the
steps
necessary
for
handling
lists
of
lists
have
been
omitted.
Such
lists
and
their
elements
must,
recursively,
be
handled
like
other
lists.
Lists
of
lists
can,
however,
not
be
represented
in
JSON-LD
using
@type
@list
must
not
;
they
have
to
be
represented
as
a
set
to
of
interlinked
node
objects
using
RDF's
xsd:string
rdf:first
and
the
resulting
value
must
have
only
a
@value
rdf:rest
property.
properties.
The
Working
Group
might
either
require
handling
of
lists-of-lists
or
forbid
them
in
JSON-LD
1.0.
Implementers
please
send
reports
of
whether
you
are
able
to
implement
handling
for
lists-of-lists
or
would
instead
request
such
structures
be
disallowed.

Overview

The
conversion
algorithm
takes
a
single
parameter
input
This
section
is
non-normative.

Algorithm

The
algorithm
takes
two
required
inputs:
an
RDF
dataset
and
a
flag
use
native
types
that
defaults
to
true
.

Construct
defaultGraph
as

Initialize
default
graph
to
a
new
JSON
object
containing
subjects
consisting
of
two
members,
nodeMap
and
listMap
,
each
,
whose
value
is
an
an
empty
JSON
object
.

Construct
graphs
as
a
Initialize
graph
map
to
an
empty
JSON
object
containing
defaultGraph
identified
by
an
empty
string
.
consisting
of
a
single
member
@default
whose
value
is
set
to
reference
default
graph
.

Reference
the
nodeMap
member
of
default
graph
using
the
variable
default
graph
nodes
.

If
graph
map
has
no
name
member,
create
one
and
set
its
value
to
a
to
a
new
entry
using
the
mechanism
described
in
Step
1
JSON
object
consisting
of
two
members,
nodeMap
and
listMap
,
whose
value
is
an
an
empty
JSON
object
.

If
property
graph
is
rdf:first
,
use
not
the
entry
in
graph.listMap
indexed
by
subject
,
initializing
it
default
graph
and
default
graph
nodes
does
not
have
a
name
member,
create
such
a
member
and
initialize
its
value
to
a
new
JSON
object
if
nesessary.
Represent
object
in
expanded
form,
as
described
with
a
single
member
@id
whose
value
is
name
.

Reference
the
value
of
the
name
member
in
Value
Expansion
.
Add
graph
map
using
the
resulting
variable
graph
object
representation
to
.

Reference
the
entry
indexed
by
first
,
value
of
the
nodeMap
member
in
graph
object
using
the
variable
node
map
and
skip
to
the
next
quad.
value
of
the
listMap
member
using
the
variable
list
map
.

For
each
RDF
triple
in
graph
consisting
of
subject
,
predicate
,
and
object
:

If
property
is
predicate
equals
rdf:rest
:
rdf:first
,

If
object
is
a
blank
node
,
use
the
entry
in
graph.listMap
indexed
by
list
map
has
no
subject
,
initializing
member,
create
one
and
initialize
it
to
a
new
an
empty
JSON
object
if
necessary.
Add
.

Initialize
the
nominalValue
value
of
object
the
first
member
of
the
subject
member
of
list
map
to
the
entry
indexed
by
rest
.
result
of
the
RDF
to
Object
Conversion
algorithm
,
passing
object
and
use
native
types
.

If
list
map
has
no
subject
member,
create
one
and
defaultGraph.subjects
does
not
contain
initialize
it
to
an
entry
for
name
,
create
a
new
entry
for
name
from
a
new
empty
JSON
object
with
key/value
pair
.

Set
value
as
Continue
with
the
entry
from
graph.subjects
for
next
RDF
triple
.

If
node
map
does
not
have
a
subject
,
initializing
it
member,
create
one
and
initialize
its
value
to
a
new
JSON
object
with
key/value
pair
consisting
of
a
single
member
@id
and
a
string
representation
whose
value
is
set
to
subject
.

Reference
the
value
of
the
subject
if
necessary.
member
in
node
map
using
the
variable
node
.

If
property
is
predicate
equals
rdf:type
,
and
the
notType
option
object
is
present
and
not
true
:
Append
the
string
representation
of
an
IRI
or
blank
node
identifier
,
append
object
to
the
array
value
for
of
the
key
@type
,
creating
member
of
node
.
If
no
such
member
exists,
create
one
and
initialize
it
to
an
entry
in
value
if
necessary.
Otherwise,
if
object
array
whose
only
item
is
rdf:nil
:
Let
key
be
object
.
Finally,
continue
to
the
string
representation
of
property
.
next
RDF
triple
.

Append
If
node
does
not
have
an
empty
@list
representation
to
the
array
predicate
member,
create
one
and
initialize
its
value
for
key
,
creating
to
an
entry
in
value
if
necessary.
empty
array
.

Otherwise,
Let
key
be
Set
value
to
the
string
representation
result
of
property
and
let
object
representation
be
using
the
RDF
to
Object
Conversion
algorithm
,
passing
object
represented
in
expanded
form
as
described
in
Value
Expansion
.
and
use
native
types
.

Add
a
reference
to
value
to
the
to
the
array
associated
with
the
predicate
member
of
node
.

Append
Set
the
head
member
of
the
object
representation
member
of
list
map
to
a
reference
of
value
.
This
reference
may
be
required
later
to
replace
the
array
value
for
key
,
creating
an
entry
in
value
if
necessary.
the
predicate
member
of
node
with
a
list
object
.

For
each
name
and
graph
object
in
graphs
:
graph
map
:

Reference
the
value
of
the
listMap
member
in
graph
object
using
the
variable
list
map
.

For
each
key-value
pair
subject
and
-
entry
in
of
the
value
associated
to
the
listMap
member
of
graph
where
object
:

If
entry
has
both
not
an
head
and
an
first
keys:
member
it
does
not
represent
the
head
of
a
list
.
Continue
with
the
next
key-value
pair.

Set
value
to
Reference
the
value
of
the
head
member
in
entry
.
using
the
variable
value
.

Remove
the
entry
for
@id
in
member
from
value
.
.

Add
an
entry
to
value
for
@list
initialized
member
to
a
new
value
and
initialize
it
to
an
array
containing
the
value
of
the
first
from
member
of
entry
.
.

While
entry
has
a
key
for
the
value
associated
with
the
rest
:
member
of
entry
is
not
rdf:nil
:

Set
rest
to
the
value
of
the
rest
member
of
entry
.

Set
entry
to
the
value
associated
with
the
rest
member
of
graph.listMap
for
entry.rest
.
list
map
.

Add
the
value
for
entry.first
associated
with
the
first
member
of
entry
to
the
list
array.
@list
member
of
value
.

Otherwise,
if
the
datatype
IRI
of
value
equals
xsd:boolean
,
set
converted
value
to
true
if
the
lexical
form
of
a
string
.
A
canonical
value
matches
true
,
or
false
if
it
matches
false
.
If
it
matches
neither,
set
type
to
xsd:boolean
.

Add
a
one-to-one
mapping
between
member
@value
to
result
whose
value
is
set
to
converted
value
.

If
type
is
not
null
,
add
a
member
@type
to
result
whose
value
is
set
to
type
.

Return
result
.

10.6
Data
Round
Tripping

When
converting
JSON-LD
to
RDF
JSON-native
numbers
are
automatically
type-coerced
to
xsd:integer
or
xsd:double
depending
on
whether
the
number
has
fractions
or
not,
the
boolean
values
true
and
false
are
coerced
to
xsd:boolean
,
and
strings
are
coerced
to
xsd:string
.
The
numeric
or
boolean
values
itself
are
converted
to
canonical
lexical
form
and
,
i.e.,
a
value
in
the
value
space
deterministic
string
representation
as
defined
in
[
XMLSCHEMA11-2
]].
In
other
words,
every
value
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
In
JavaScript,
implementers
can
use
the
following
snippet
of
code:
code
to
convert
an
integer
to
canonical
lexical
form
:

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
be
is
a
decimal
number.
The
number
and
the
exponent
must
be
is
an
integer.
Leading
zeroes
zeros
and
a
preceding
plus
sign
(
+
)
are
prohibited
in
the
exponent.
If
the
exponent
is
zero,
it
must
be
is
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
.
To
convert
the
number
in
JavaScript,
implementers
can
use
the
following
snippet
of
code:
Example
24
(value).toExponential().replace(/e\+?/,'E')
xsd:double
's
value
space
is
defined
by
the
IEEE
double-precision
64-bit
floating
point
type
[
IEEE-754-1985
].
Note
When
data
such
as
decimals
need
to
be
normalized,
JSON-LD
authors
should
]
whereas
the
value
space
of
JSON
numbers
is
not
use
values
that
are
going
specified;
when
converting
JSON-LD
to
undergo
automatic
conversion.
This
RDF
the
mantissa
is
due
rounded
to
15
digits
after
the
lossy
nature
of
xsd:double
values.
Authors
should
instead
decimal
point.
In
JavaScript,
implementers
can
use
the
expanded
object
form
following
snippet
of
code
to
set
the
convert
a
double
to
canonical
lexical
form
directly.
:

When
JSON-native
datatypes,
like
number
s,
numbers
,
are
type
coerced,
converted
to
RDF,
lossless
data
round-tripping
can
not
be
guaranted.
Consider
guaranteed
as
rounding
errors
might
occur.
When
converting
RDF
to
JSON-LD
,
similar
rounding
errors
might
occur.
Furthermore,
the
following
code
example:
var myObj1 = {
"@context": {
"number": {
"@id": "http://example.com/vocab#number",
}
},
"number" :
};
// Convert the JSON-LD document to RDF; this converts 42 to a string
var jsonldText = jsonld.toRDF(myObj1, myRdfTripleCollector);
// Convert the RDF triples back to a JavaScript object
var
myObj2
=
jsonld.fromRDF(myRdfTripleCollector.getTriples());
At
this
point,
myObj1
and
myObj2
will
have
different
values
for
datatype
or
the
"number"
property.
lexical
representation
might
be
lost.
An
myObj1
xsd:double
will
have
the
number
42
,
while
with
a
value
of
myObj2
2.0
have
will,
e.g.,
result
in
an
object
consisting
of
@value
xsd:integer
set
to
the
string
with
a
value
of
"42"
2
in
canonical
lexical
form
when
converted
from
RDF
to
JSON-LD
and
back
to
RDF.
It
is
important
to
highlight
that
in
practice
it
might
be
impossible
to
losslessly
convert
an
@type
xsd:integer
set
to
a
number
because
its
value
space
is
not
limited.
While
the
JSON
specification
[
RFC4627
]
does
not
limit
the
expanded
value
space
of
xsd:nonNegativeInteger
.
numbers
either,
concrete
implementations
typically
do
have
a
limited
value
space.

Note

To
ensure
lossless
round-tripping
the
Converting
from
RDF
algorithm
specifies
a
use
native
types
flag
which
controls
whether
RDF
literals
with
a
datatype
IRI
equal
to
xsd:integer
,
xsd:double
,
or
xsd:boolean
are
converted
to
their
JSON-native
counterparts.
If
the
use
native
types
flag
is
set
to
false
,
all
literals
remain
in
their
original
string
representation.

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
backslash-escape
forward
slashes.
slashes
MUST
NOT
be
backslash-escaped.

A.
11.
Initial
Context
The
Application
Programming
Interface

This
API
provides
a
clean
mechanism
that
enables
developers
to
convert
JSON-LD
data
into
a
variety
of
output
formats
that
are
often
easier
to
work
with.
A
conformant
JSON-LD
API
Implementation
MUST
implement
the
entirety
of
the
following
API.

The
JsonLdProcessor
interface
is
the
high-level
programming
structure
that
developers
use
to
access
the
JSON-LD
transformation
methods.

It
is
important
to
highlight
that
conformant
JSON-LD
API
Implementations
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.

Issue
8
Feature
at
Risk
5
:
Use
of
method
overloading
to
make
the
options
parameter
optional

The
definition
of
the
JsonLdProcessor
interface
uses
method
overloading
to
make
the
"options"
parameter
optional.
According
to
the
current
version
of
the
Web
IDL
specification
[
WEBIDL
],
this
would
not
be
supported
as
the
"options"
parameter
(a
dictionary)
and
the
callback
parameter
(a
callback
function)
are
not
distinguishable
.
A
bug
report
has
been
already
been
filed.
If
it
turns
out
that
this
is
not
a
bug,
the
Working
Group
may
change
the
interface
by
swapping
the
"options"
and
"callback"
parameter.

Methods

If
the
passed
input
is
a
DOMString
representing
the
IRI
of
a
remote
document,
dereference
it.
If
the
retrieved
document
has
a
content
type
different
than
application/ld+json
or
application/json
or
if
the
document
cannot
be
parsed
as
JSON,
invoke
the
callback
passing
an
loading
document
failed
error.

If
the
passed
input
is
a
DOMString
representing
the
IRI
of
a
remote
document,
dereference
it.
If
the
retrieved
document
has
a
content
type
different
than
application/ld+json
or
application/json
or
if
the
document
cannot
be
parsed
as
JSON,
invoke
the
callback
passing
an
loading
document
failed
error.

If
the
passed
input
is
a
DOMString
representing
the
IRI
of
a
remote
document,
dereference
it.
If
the
retrieved
document
has
a
content
type
different
than
application/ld+json
or
application/json
or
if
the
notion
document
cannot
be
parsed
as
JSON,
invoke
the
callback
passing
an
loading
document
failed
error.

The
base
IRI
to
use
when
expanding
or
compacting
the
document.
This
overrides
the
value
of
input
if
it
is
an
IRI
.
If
not
specified
and
input
is
not
an
IRI
,
the
base
IRI
defaults
to
the
current
document
IRI
if
in
a
browser
context,
or
the
empty
string
if
there
is
no
document
context.

The
default
value
of
base
in
JsonLdOptions
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.
Based
on
implementer
feedback,
the
Working
Group
may
decide
to
change
the
default
value
to
null
,
meaning
that
IRIs
are
not
automatically
compacted
to
relative
IRIs.

The
callback
of
the
context
loader
to
be
used
to
retrieve
remote
contexts.
If
specified,
it
must
MUST
be
specified
external
used
to
retrieve
remote
contexts;
otherwise,
if
not
specified,
the
processor's
built-in
context
loader
MUST
be
used.

If
set
to
json-ld-1.0
,
the
JSON-LD
Syntax
processor
MUST
produce
exactly
the
same
results
as
the
algorithms
defined
in
this
specification.
If
set
to
another
value,
the
JSON-LD
processor
is
allowed
to
extend
or
modify
the
algorithms
defined
in
this
specification
at
to
enable
application-specific
optimizations.
The
definition
of
such
optimizations
is
beyond
the
scope
of
this
specification
and
thus
not
defined.
Consequently,
different
implementations
MAY
implement
different
optimizations.
Developers
MUST
NOT
define
modes
beginning
with
json-ld
as
they
are
reserved
for
future
versions
of
this
specification.

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
.

B.
A.
Acknowledgements

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,
RDFj.
The
work
of
Dave
Lehn
and
Mike
Johnson
who
reviewed,
provided
feedback,
are
appreciated
for
reviewing,
and
performed
performing
several
implementations
of
the
specification,
and
specification.
Ian
Davis,
who
created
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
for
their
input
on
the
specification.