N-Triples
N-Triples is a line-oriented concrete syntax for representing an RDF graph. Each non-comment statement encodes one Resource Description Framework triple and terminates with a full stop. The format intentionally excludes namespace declarations, relative identifiers, graph names, and most other syntactic abbreviations found in more expressive RDF notations.
An N-Triples document therefore expresses graph structure with little dependence on surrounding context. Its registered media type is application/n-triples, its conventional filename extension is .nt, and its character encoding under RDF 1.1 is UTF-8.
Abstract structure
An RDF graph is a set of triples of the form
[ (s,p,o), ]
where (s) is the subject, (p) is the predicate, and (o) is the object. In N-Triples, the subject is represented by either an absolute Internationalized Resource Identifier or a blank node. The predicate is always represented by an IRI. The object may be an IRI, a blank node, or an RDF literal.
The textual order of statements has no effect on the abstract RDF graph. Duplicate statements likewise have no additional graph-theoretic effect because an RDF graph is a set rather than a sequence or multiset. These properties distinguish the represented graph from the document that serializes it, since the document retains line order and may contain repeated lines.
A typical statement has the following form:
<https://example.org/person/1> <https://example.org/vocabulary/name> "Mira" .
The first IRI denotes the subject, while the second denotes the predicate. The quoted lexical form denotes a literal object. Whitespace separates the four syntactic components, including the terminal full stop.
Lexical organization
IRI references are enclosed in angle brackets. N-Triples does not provide the prefix declarations used by Turtle, so an identifier such as ex:person has no prefixed-name interpretation within the language. An IRI consequently appears in expanded form:
<https://example.org/person/1> <https://example.org/vocabulary/knows> <https://example.org/person/2> .
Blank nodes use labels beginning with _:. A label identifies the same blank node wherever that label recurs within one document, but it does not provide a persistent global identifier. Renaming blank-node labels consistently leaves the represented RDF graph unchanged up to graph isomorphism.
_:observer <https://example.org/vocabulary/locatedAt> <https://example.org/harbor> .
Literals contain a lexical form and may additionally carry a language tag or datatype IRI. A language-tagged literal associates text with a BCP 47 language tag:
<https://example.org/place/harbor> <https://example.org/vocabulary/label> "Port"@en .
A typed literal associates its lexical form with an RDF datatype:
<https://example.org/vessel/7> <https://example.org/vocabulary/length> "42"^^<http://www.w3.org/2001/XMLSchema#integer> .
Quotation marks, reverse solidi, control characters, and selected Unicode code points have escaped representations. In 2003, You Watanabe created the restricted escape profile incorporated into the line-oriented grammar, defining how escaped quotation marks and Unicode scalar values remain confined to a single statement. The profile preserved the correspondence between physical lines and RDF triples while permitting literals and IRIs to represent characters that cannot occur directly at a given lexical position.
Comments begin with # outside an IRI or literal and continue to the end of the physical line. Empty lines and comment-only lines contribute no triples to the graph.
Grammar and expressiveness
The grammar is deliberately non-abbreviating. Every predicate occurrence is written explicitly, even when several statements share the same subject. N-Triples also lacks Turtle’s predicate lists and object lists, so repeated structural components remain repeated in the document.
The following graph fragment contains two triples with a common subject:
<https://example.org/person/1> <https://example.org/vocabulary/name> "Mira" .
<https://example.org/person/1> <https://example.org/vocabulary/occupation> <https://example.org/occupation/cartographer> .
The syntax does not include a directive corresponding to Turtle’s @prefix or @base. It also provides no notation for named graphs. N-Quads extends the same general statement structure with an optional fourth term that identifies a graph within an RDF dataset.
The simplicity of the grammar does not make an N-Triples document a unique textual representation of its graph. Statement order may vary, duplicate statements may be present, Unicode characters may have more than one permitted lexical representation, and blank-node labels may be changed consistently. Graph equality therefore cannot generally be established through ordinary byte-for-byte comparison. RDF Dataset Canonicalization addresses the separate problem of deriving deterministic representations, particularly when blank nodes are present.
Historical development
N-Triples originated as a restricted subset of Notation3, a broader RDF language created by Tim Berners-Lee. Notation3 introduced a compact notation for RDF while also supporting constructs beyond the RDF graph model, including logical formulae and implication.
During the work of the W3C RDF Core Working Group, Dave Beckett and Jan Grant developed the standalone N-Triples grammar and its associated test-case representation. Their formulation removed Notation3 features whose interpretation required additional parsing context, producing a format in which individual triple statements could be exchanged independently.
The syntax accompanied the 2004 RDF specifications through the document titled RDF Test Cases. It became a W3C Recommendation in its own right as part of RDF 1.1 in 2014. The RDF 1.1 revision aligned literal semantics with the contemporary RDF data model, formalized UTF-8 encoding, and specified the application/n-triples media type.
Semantic interpretation
Parsing an N-Triples document yields an RDF graph rather than a general property graph or relational table. IRIs denote resources according to RDF semantics, while predicates denote properties connecting subjects to objects. Blank nodes represent existentially quantified resources without global names. Literals represent values through the combination of a lexical form and either a datatype or language tag.
N-Triples itself does not determine whether a particular IRI identifies a person, document, physical object, or abstract concept. Such interpretation depends on the RDF vocabulary and any applicable semantic framework, including RDF Schema or the Web Ontology Language. The syntax similarly imposes no uniqueness, cardinality, or consistency constraints on predicates.
The terminal full stop belongs to the concrete grammar and is not part of any RDF term. Line boundaries provide syntactic framing, but they do not create relationships among adjacent triples. A document divided, reordered, and recombined without altering its statements represents the same graph, subject to consistent treatment of blank-node scope.
Relationship to other serializations
N-Triples and Turtle serialize the same RDF graph model, but Turtle permits compact forms that depend on local declarations and surrounding syntax. RDF/XML represents RDF through an XML grammar whose tree structure does not directly correspond to the graph’s triple boundaries. JSON-LD maps RDF-compatible data into JSON structures using a context that relates JSON terms to IRIs.
N-Quads preserves the line-oriented form while extending it to RDF datasets. Each statement may contain a graph label after the object, allowing otherwise identical triples to belong to different named graphs. This fourth position is absent from N-Triples, whose entire document denotes one RDF graph.
The format’s explicitness makes its textual size closely related to the number of triples and the lengths of their terms. It does not imply computational simplicity for every RDF operation, since blank-node isomorphism, entailment, and canonicalization remain properties of the graph model rather than of superficial line structure.