Install
openclaw skills install json-to-triples-converterConvert JSON documents into RDF triples or graph-ready subject–predicate–object statements for knowledge graphs and semantic databases.
openclaw skills install json-to-triples-converterTransform JSON documents into RDF triples and graph-ready structures.
This skill converts hierarchical JSON data into subject–predicate–object triples, enabling the data to be ingested into knowledge graphs, semantic web systems, and graph databases. The generated triples can be exported in multiple formats including RDF Turtle, N-Triples, JSON-LD, and Graph JSON.
Input JSON:
{
"person": {
"name": "Alice",
"age": 30,
"email": "alice@example.com",
"company": {
"name": "Acme Corp",
"industry": "Technology"
}
}
}
Generated RDF Triples (Turtle):
@prefix ex: <http://example.org/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix schema: <http://schema.org/> .
ex:person_alice a foaf:Person ;
foaf:name "Alice" ;
foaf:age 30 ;
foaf:mbox "alice@example.com" ;
schema:worksFor ex:company_acme .
ex:company_acme a schema:Organization ;
foaf:name "Acme Corp" ;
schema:industry "Technology" .
Analyze the JSON document to understand:
Detect entities that represent real-world objects:
Create unique URIs for each entity:
Person "Alice" → ex:person_alice
Company "Acme" → ex:company_acme
Location "New York" → ex:location_newyork
Map JSON keys to RDF predicates:
"name" → foaf:name
"age" → foaf:age
"worksFor" → schema:worksFor
"email" → foaf:mbox
Generate appropriate object values:
Literal values: "Alice", 30, true
References: ex:company_acme (URI reference)
Typed literals: "2024-04-09"^^xsd:date
Convert nested objects to relationships:
{
"employee": {
"name": "Alice",
"manager": {
"name": "Bob"
}
}
}
Becomes:
ex:employee_alice schema:manager ex:person_bob .
Ensure shared entities are represented once:
{"name": "Alice", "age": 30}
↓
ex:subject foaf:name "Alice" .
ex:subject foaf:age 30 .
{"person": {"name": "Alice", "company": {"name": "Acme"}}}
↓
ex:person_alice foaf:name "Alice" .
ex:person_alice ex:worksAt ex:company_acme .
ex:company_acme foaf:name "Acme" .
{"tags": ["python", "graph", "rdf"]}
↓
ex:subject ex:tag "python" .
ex:subject ex:tag "graph" .
ex:subject ex:tag "rdf" .
{"age": 30, "created": "2024-04-09"}
↓
ex:subject foaf:age "30"^^xsd:integer .
ex:subject schema:dateCreated "2024-04-09"^^xsd:date .
@prefix ex: <http://example.org/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
ex:subject foaf:name "Alice" .
ex:subject foaf:age 30 .
ex:subject foaf:workplaceHomepage ex:company .
<http://example.org/subject> <http://xmlns.com/foaf/0.1/name> "Alice" .
<http://example.org/subject> <http://xmlns.com/foaf/0.1/age> "30"^^<http://www.w3.org/2001/XMLSchema#integer> .
{
"@context": {
"@vocab": "http://schema.org/",
"foaf": "http://xmlns.com/foaf/0.1/"
},
"@type": "Person",
"@id": "http://example.org/subject",
"foaf:name": "Alice",
"foaf:age": 30
}
{
"nodes": [
{"id": "person_alice", "type": "Person", "properties": {"name": "Alice", "age": 30}},
{"id": "company_acme", "type": "Organization", "properties": {"name": "Acme"}}
],
"edges": [
{"source": "person_alice", "target": "company_acme", "type": "worksFor"}
]
}
foaf: http://xmlns.com/foaf/0.1/
schema: http://schema.org/
rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
rdfs: http://www.w3.org/2000/01/rdf-schema#
owl: http://www.w3.org/2002/07/owl#
xsd: http://www.w3.org/2001/XMLSchema#
dbo: http://dbpedia.org/ontology/
namespaces:
ex: http://example.org/
myapp: http://myapp.example.org/
custom: http://custom.vocabulary.org/
String values → xsd:string
Numbers (integer) → xsd:integer
Numbers (float) → xsd:decimal
Booleans → xsd:boolean
ISO dates → xsd:date / xsd:dateTime
URIs → xsd:anyURI
{"title": {"en": "Alice", "fr": "Aline"}}
↓
ex:subject rdfs:label "Alice"@en .
ex:subject rdfs:label "Aline"@fr .
✓ Use consistent namespace URIs
✓ Generate meaningful entity identifiers
✓ Normalize entity names to prevent duplicates
✓ Use standard vocabularies (schema.org, FOAF)
✓ Include language tags for multilingual content
✓ Type literal values appropriately
✓ Document custom vocabulary mappings
✓ Validate triples before output
✓ Handle nested structures recursively
✓ Manage URIs consistently
The generated triples feed into:
See conversion-patterns.md for detailed JSON-to-triples conversion patterns and example-conversions.md for complete real-world examples.
Version: 1.0.0