Literals and Types

Strings, numbers, booleans, dates, and how values are typed.

When the object of a triple is a value (not another resource), it's called a literal. Literals can be typed to indicate what kind of value they hold.

The examples on this page use the following prefixes:

@prefix people: <https://example.org/people/> .
@prefix vocab:  <https://example.org/vocab/> .
@prefix xsd:    <http://www.w3.org/2001/XMLSchema#> .

Strings

A string in double quotes:

people:alice vocab:name "Alice Chen" .

This is the most common kind of literal. Without an explicit type, it's treated as a string.

Typed Literals

Append ^^ and a type to give a literal an explicit type:

people:alice
    vocab:age "32"^^xsd:integer ;
    vocab:active "true"^^xsd:boolean ;
    vocab:joined "2024-03-15"^^xsd:date ;
    vocab:salary "95000.00"^^xsd:decimal .

The ^^ says "interpret this value as this type." Without it, "32" is just the text characters 3 and 2. With ^^xsd:integer, it's the number thirty-two.

Common Types

TypeExampleWhat it represents
xsd:string"hello"Text
xsd:integer"42"^^xsd:integerWhole number
xsd:decimal"3.14"^^xsd:decimalDecimal number
xsd:boolean"true"^^xsd:booleanTrue or false
xsd:dateTime"2025-03-15T10:30:00Z"^^xsd:dateTimeDate and time
xsd:date"2025-03-15"^^xsd:dateDate without time
xsd:anyURI"https://example.org"^^xsd:anyURIA URI stored as a value

Numbers can also be written without quotes and the type is inferred:

people:alice
    vocab:age 32 ;          # xsd:integer
    vocab:score 4.5 ;       # xsd:decimal
    vocab:active true .     # xsd:boolean

Why Types Matter

Types affect how values are compared, sorted, and validated. The string "32" and the integer 32 are not the same thing. Sorting strings puts "9" after "10" (alphabetically). Sorting integers puts 9 before 10 (numerically).

Types also matter for constraints. A validation rule that says "age must be an integer" will flag "thirty-two" as invalid but accept 32.

Literals vs Resources

A literal is a value. A resource is a thing with its own identity that can have its own properties.

# Literal: status is a string value
projects:q3 vocab:status "active" .

# Resource: status is a thing you can describe further
projects:q3 vocab:status vocab:Active .
vocab:Active vocab:label "Active" .
vocab:Active vocab:description "Currently being worked on." .

With a literal, you have a value. With a resource, you have something you can say more about. The Individuals page covers when to use which.

See Also

  • Triples: how literals fit into the triple structure
  • Individuals: when to use resources instead of literals

On this page