Exporting data

Data can be exported in several ways and formats.

JSON-LD and NDJSON-LD export forms

To export flattened, framed, or compacted document forms, you should also provide a context, a frame, or both as a file or a link. Use the graphdb.jsonld.whitelist GraphDB configuration property inside the graphdb.properties config file to provide a whitelist with URLs that are permitted for JSON-LD and NDJSON-LD processing.

The whitelist is a comma-separated list of URLs. The wildcard (*) allows for fine-grained control, enabling administrators to specify a set of URLs, including entire directories. Each entry in the list represents a source that is considered safe for JSON-LD operations.

# Sets whitelist for JSON-LD and NDJSON-LD resources
graphdb.jsonld.whitelist = https://example.com/my/jsonld/*, file:///usr/local/my/jsonld/*

Note

A pop-up for selecting the form appears when exporting to JSON-LD or NDJSON-LD from Workbench. If you’ve selected flattened or compacted forms, a field for providing an address or file path to the context also appears. When a framed form is selected, a field for the path to the frame will appear instead.

Exporting a repository

  1. Go to Explore ‣ Graphs overview.

  2. Click Export repository and then select the serialization to use for the exported file.

_images/export_repository.png

Exporting individual graphs

  1. Go to Explore ‣ Graphs overview.

  2. A list of contexts (graphs) in a repository is displayed. You can also search for particular graphs from the search field at the top of the screen.

  3. After you click the checkboxes of one or more listed graphs, clicking Export selected graphs icon-gdb-export will prompt you to indicate a serialization format and then save a file in that format with the selected graphs.

To export a single graph, click the Export graph icon icon-gdb-export on the right side of its row on the display. To export multiple graphs, click their check boxes on the left to select them click the Export selected graphs icon icon-gdb-export at the top of the list.

_images/export_TriG.png

Exporting query results

You can export SPARQL query results from the SPARQL view by clicking the Download As button on the right side of the screen. The list of export formats will be RDF serializations after you execute a CONSTRUCT query or JSON, XML, CSV, and TSV formats after executing a SELECT query.

Exporting resources

After finding a resource from the View resource on GraphDB’s home page, you can download its RDF triples in a format of your choice by clicking the Download As button on the right side of the screen:

_images/export_resource.png

Exporting via HTTP with curl

Using the curl command line utility lets you take advantage of GraphDB’s RDF4J REST API to export repository data and queries from your operating system command line.

Request headers

  • Accept: Relevant values for GET requests are the MIME types of the supported RDF formats.

  • Content-Type: When exporting graph queries, used to specify the encoding of any request data sent to a server. Relevant values are the MIME types of the supported RDF formats.

  • Link: Used only when exporting to JSON-LD or NDJSON-LD document form. When importing or exporting to compacted or flattened JSON-LD or NDJSON-LD document form, address or file path of context. When exporting to framed JSON-LD or NDJSON-LD document form, address or file path of frame that should be used by the Framing processor.

If a link is not provided when exporting to the JSON-LD or NDJSON serializations:

  • Exporting to compacted JSON-LD / NDJSON-LD document form — exported data will use the namespaces of the repository instead.

  • Exporting to flattened JSON-LD / NDJSON-LD document form — exported data will not contain context.

  • Exporting to framed JSON-LD / NDJSON-LD document form — exported data will be exported to expanded JSON-LD or NDJSON-LD document form instead.

Fetch statements from repository

GET /repositories/<repo_id>/statements

Example:

curl '<base_url>/repositories/<repo_id>/statements' --header 'Accept: <MIME-type>/<MIME-subtype>'

Export JSON-LD using context example:

curl '<base_url>/repositories/<repo_id>/statements' \
--header 'Accept: application/ld+json; profile=http://www.w3.org/ns/json-ld#<type-of-mode>' \
--header 'Link: <link_to_the_context_location>; rel="http://www.w3.org/ns/json-ld#context"'

Warning

The link to the context or frame location must be surrounded by angle brackets <>. From the example above, replace only link_to_the_context_location with your link.

The following example would not work:

--header 'Link: http://localhost:7200/json-ld-11/context.jsonld; rel="http://www.w3.org/ns/json-ld#context"'

Instead, it should be written like this:

--header 'Link: <http://localhost:7200/json-ld-11/context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"'

Export JSON-LD using frame example:

curl '<base_url>/repositories/<repo_id>/statements' \
--header 'Accept: application/ld+json;profile=http://www.w3.org/ns/json-ld#framed' \
--header 'Link: <link_to_the_frame_location>; rel="http://www.w3.org/ns/json-ld#frame"'

Fetch queries from repository

GET /repositories/<repo_id>/

The query can be specified with --data-raw. It can also be provided with --data-urlencode query@/<path-to-query-file>

Example:

curl '<base_url>/repositories/<repo_id>' \
--header 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
--header 'Accept: application/<MIME-type>' \
--data-raw $'query=<sparql-query>'

Export JSON-LD example:

curl '<base_url>/repositories/<repo_id>' \
--header 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
--header 'Accept: application/ld+json; profile=http://www.w3.org/ns/json-ld#<type-of-mode>' \
--header 'Link: <link_to_the_context_location>; rel="http://www.w3.org/ns/json-ld#context"' \
--data-raw $'query=<sparql-query>'

Warning

The link to the context or frame location must be surrounded by angle brackets <>. From the example above, replace only link_to_the_context_location with your link.

The following example would not work:

--header 'Link: http://localhost:7200/json-ld-11/context.jsonld; rel="http://www.w3.org/ns/json-ld#context"'

Instead, it should be written like this:

--header 'Link: <http://localhost:7200/json-ld-11/context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"'

Configuring the JSON-LD writer properties

The JSON-LD writer has additional properties that configure how the writer operates:

Property name

Description

Default value

com.ontotext.graphdb.rio.jsonld_processing_mode

Defines whether the writer will use JSON-LD 1.0 or JSON-LD 1.1 specifications when processing JSON-LD exports.

V1_1

com.ontotext.graphdb.rio.jsonld.frame

Provides a path to a frame that is used when exporting to framed document form.

null

com.ontotext.graphdb.rio.jsonld.compact_to_relative

Determines if IRIs are compacted relative to the base option or document location when compacting.

TRUE

com.ontotext.graphdb.rio.jsonld.expand_context

Provides a path to a context that is used to expand the active context when expanding a document.

null

com.ontotext.graphdb.rio.jsonld.ordered

If set to TRUE, certain algorithm processing steps are ordered lexicographically where indicated. If set to FALSE, order is not considered during processing.

FALSE

com.ontotext.graphdb.rio.jsonld.explicit

Indicates whether the output should be in explicit form. When set to TRUE, the output will include redundant information to improve human readability.

FALSE

com.ontotext.graphdb.rio.jsonld_embed

When set to ALWAYS, node objects are embedded as property values, unless this would cause a circular reference. When set to NEVER, node references are used when serializing matching values. When set to ONCE, only a single value within a given node object will be embedded, and other values of other properties will use a node reference.

ONCE

com.ontotext.graphdb.rio.jsonld.omit_default

Controls whether default values are omitted from the output.

FALSE

com.ontotext.graphdb.rio.jsonld.omit_graph

Controls whether the top-level graph is omitted from the output.

TRUE

com.ontotext.graphdb.rio.jsonld.require_all

Specifies whether all properties are considered as required.

FALSE

com.ontotext.graphdb.rio.jsonld.numeric_id

Allows the use of numeric values as @id in the exported JSON-LD document.

FALSE

com.ontotext.graphdb.rio.jsonld.url_validation

Specifies whether URI validation is enabled. When set to TRUE, URI validation is performed during JSON-LD processing.

TRUE