N-Triples is a line-based, plain text format for encoding an RDF graph.

N-Triples

This section defines an easy to parse line-based subset of Turtle named N-Triples.

The syntax is a revised version of N-Triples as originally defined in the RDF Test Cases [[!RDF-TESTCASES]] document. Its original intent was for writing test cases, but it has proven to be popular as a exchange format for RDF data.

An N-Triples document contains no parsing directives.

N-Triples triples are a sequence of RDF terms representing the subject, predicate and object of an RDF Triple. These may be seperated by white space (spaces #x20 or tabs #x9). This sequence is terminated by a '.' and a new line (optional at the end of a document).

N-Triples triples are also Turtle simple triples, but Turtle includes other representations of RDF Terms and abbreviations of RDF Triples. When parsed by a Turtle parser, data in the N-Triples format will produce exactly the same triples as a parser for the restricted N-triples language.

The RDF graph represented by an N-Triples document contains exactly each triple matching N-Triples triple production.

Summary of diffrences in N-Triples and Turtle

Triples

N-Triples only allows for simple triple statements which MUST NOT contain new lines. A single triple is always a single line of the document.

IRI Representations

Turtle N-Triples example
absolute IRI yes yes <http://a.example/some/path/>
relative IRI yes no </some/path/>
prefixed name yes no rdfs:label
a for the predicate rdf:type yes no a

Literal Representations

Turtle N-Triples example
single-quoted single-line lexical representation yes no 'some literal'
double-quoted single-line lexical representation yes yes "some literal"
single-quoted multi-line lexical representation yes no '''some
literal'''
double-quoted multi-line lexical representation yes no """some
literal"""
abbreviated numeric yes no 13
abbreviated boolean yes no true

Summary of Blank Node Representations in N-Triples and Turtle

Turtle N-Triples example
labeled blank node yes yes <http://a.example/who#Alice> foaf:knows _:bob .
anonymous node yes no <http://a.example/who#Alice> foaf:knows [] .
blank node property list yes no <http://a.example/who#Alice> foaf:knows [ foaf:name "Bob" ] .

Changes from RDF Test Cases format

Grammar

A N-Triples document is a Unicode[[!UNICODE]] character string encoded in UTF-8. Unicode codepoints only in the range U+0 to U+10FFFF inclusive are allowed.

The EBNF used here is defined in XML 1.0 [[!EBNF-NOTATION]].

Escape sequence rules are the same as Turtle. However, as only the STRING_LITERAL2 production is allowed new lines in literals MUST be escaped.

Media Type and Content Encoding

The media type of N-Triples is application/n-triples. The content encoding of N-Triples is always UTF-8. See N-Triples Media Type for the media type registration form.

Other Media Types

N-Triples has been historically provided with other media types. N-Triples may also be provided as text/plain. When used in this way N-Triples MUST use the escaped form of any character outside US-ASCII. As N-Triples is a subset of Turtle a N-Triples document MAY also be provided as text/turtle. In both of these cases the document is not an N-Triples document as an N-Triples document is only provided as application/n-triples.

N-Triples Internet Media Type, File Extension and Macintosh File Type

Contact:
????
See also:
How to Register a Media Type for a W3C Specification
Internet Media Type registration, consistency of use
TAG Finding 3 June 2002 (Revised 4 September 2002)

The Internet Media Type / MIME Type for N-Triples is "application/n-triples".

It is recommended that N-Triples files have the extension ".nt" (all lowercase) on all platforms.

It is recommended that N-Triples files stored on Macintosh HFS file systems be given a file type of "TEXT".

This information that follows will be submitted to the IESG for review, approval, and registration with IANA.

Type name:
application
Subtype name:
n-triples
Required parameters:
None
Optional parameters:
None
Encoding considerations:
The syntax of N-Triples is expressed over code points in Unicode [[!UNICODE]]. The encoding is always UTF-8 [[!UTF-8]].
Unicode code points may also be expressed using an \uXXXX (U+0 to U+FFFF) or \UXXXXXXXX syntax (for U+10000 onwards) where X is a hexadecimal digit [0-9A-F]
Security considerations:
N-Triples is a general-purpose assertion language; applications may evaluate given data to infer more assertions or to dereference IRIs, invoking the security considerations of the scheme for that IRI. Note in particular, the privacy issues in [[!RFC3023]] section 10 for HTTP IRIs. Data obtained from an inaccurate or malicious data source may lead to inaccurate or misleading conclusions, as well as the dereferencing of unintended IRIs. Care must be taken to align the trust in consulted resources with the sensitivity of the intended use of the data; inferences of potential medical treatments would likely require different trust than inferences for trip planning.
N-Triples is used to express arbitrary application data; security considerations will vary by domain of use. Security tools and protocols applicable to text (e.g. PGP encryption, MD5 sum validation, password-protected compression) may also be used on N-Triples documents. Security/privacy protocols must be imposed which reflect the sensitivity of the embedded information.
N-Triples can express data which is presented to the user, for example, RDF Schema labels. Application rendering strings retrieved from untrusted N-Triples documents must ensure that malignant strings may not be used to mislead the reader. The security considerations in the media type registration for XML ([[!RFC3023]] section 10) provide additional guidance around the expression of arbitrary data and markup.
N-Triples uses IRIs as term identifiers. Applications interpreting data expressed in N-Triples should address the security issues of Internationalized Resource Identifiers (IRIs) [[!RFC3987]] Section 8, as well as Uniform Resource Identifier (URI): Generic Syntax [[!RFC3986]] Section 7.
Multiple IRIs may have the same appearance. Characters in different scripts may look similar (a Cyrillic "о" may appear similar to a Latin "o"). A character followed by combining characters may have the same visual representation as another character (LATIN SMALL LETTER E followed by COMBINING ACUTE ACCENT has the same visual representation as LATIN SMALL LETTER E WITH ACUTE). Any person or application that is writing or interpreting data in Turtle must take care to use the IRI that matches the intended semantics, and avoid IRIs that make look similar. Further information about matching of similar characters can be found in Unicode Security Considerations [[UNISEC]] and Internationalized Resource Identifiers (IRIs) [[RFC3987]] Section 8.
Interoperability considerations:
There are no known interoperability issues.
Published specification:
This specification.
Applications which use this media type:
No widely deployed applications are known to use this media type. It may be used by some web services and clients consuming their data.
Additional information:
Magic number(s):
None.
File extension(s):
".nt"
Macintosh file type code(s):
"TEXT"
Person & email address to contact for further information:
Eric Prud'hommeaux <eric@w3.org>
Intended usage:
COMMON
Restrictions on usage:
None
Author/Change controller:
The N-Triples specification is the product of the RDF WG. The W3C reserves change control over this specifications.