# Supported Import and Export Formats in Microsoft Ontology Playground: RDF, JSON, and YAML

> Explore supported import and export formats like RDF, JSON, and YAML in Microsoft Ontology Playground. Learn how to use these formats for your ontology projects.

- Repository: [Microsoft/Ontology-Playground](https://github.com/microsoft/Ontology-Playground)
- Tags: api-reference
- Published: 2026-07-23

---

**Microsoft Ontology Playground supports importing RDF/OWL and legacy JSON formats while exporting to JSON, RDF/XML, YAML, and CSV through a React-based modal interface with specialized serialization utilities.**

Microsoft Ontology Playground is an open-source ontology management tool that enables seamless data exchange via multiple standardized formats. Understanding the supported import and export formats is crucial for integrating ontologies into semantic web workflows and enterprise systems like Microsoft Fabric. The application handles format detection, parsing, and serialization through specific components in [`src/components/ImportExportModal.tsx`](https://github.com/microsoft/Ontology-Playground/blob/main/src/components/ImportExportModal.tsx) and dedicated RDF utilities in [`src/lib/rdf/serializer.ts`](https://github.com/microsoft/Ontology-Playground/blob/main/src/lib/rdf/serializer.ts).

## Import Formats: RDF, OWL, and Legacy JSON

The import pipeline in [`ImportExportModal.tsx`](https://github.com/microsoft/Ontology-Playground/blob/main/ImportExportModal.tsx) processes ontology definitions via drag-and-drop or file selection, automatically detecting formats based on file extensions and content signatures.

### RDF and OWL Files

The primary import format is **RDF/XML** and **OWL** files with `.rdf`, `.owl`, or `.iq` extensions. When a file is selected, the application checks for XML start tags (`<?xml` or `<rdf:RDF`) or recognized extensions, then invokes `parseRDF(content)` to transform the markup into an internal ontology object and data bindings array.

### Legacy JSON Import

**JSON import** is available as a legacy option gated by the `VITE_ENABLE_LEGACY_FORMATS` environment variable. When `LEGACY_FORMATS_ENABLED` evaluates to `true`, the modal falls back to `JSON.parse` for files that don't match RDF patterns, extracting the ontology and bindings structure directly from the parsed JSON object.

## Export Formats: JSON, RDF/XML, YAML, and CSV

The `handleExport()` function in [`ImportExportModal.tsx`](https://github.com/microsoft/Ontology-Playground/blob/main/ImportExportModal.tsx) generates downloadable files through format-specific serialization paths using the current ontology state from the Zustand store ([`appStore.ts`](https://github.com/microsoft/Ontology-Playground/blob/main/appStore.ts)).

### JSON Export

The **JSON format** uses `exportOntology()` from [`appStore.ts`](https://github.com/microsoft/Ontology-Playground/blob/main/appStore.ts), which applies `JSON.stringify` to the in-memory `{ ontology, bindings }` object. This produces a machine-readable representation suitable for programmatic consumption and API integrations.

### RDF/XML (OWL) Serialization

For **RDF/XML export**, the modal calls `serializeToRDF(currentOntology, dataBindings)` from [`src/lib/rdf/serializer.ts`](https://github.com/microsoft/Ontology-Playground/blob/main/src/lib/rdf/serializer.ts). This utility constructs standards-compliant OWL documents with proper namespace declarations, emitting `<owl:Class>`, `<owl:DatatypeProperty>`, and `<owl:ObjectProperty>` elements alongside custom ontology annotations.

### YAML Export

The **YAML format** is generated by `exportAsYAML()` within the modal component, which traverses the ontology tree to produce human-readable YAML strings without external dependencies. This format includes entity types, relationships, properties, and optional data bindings in a structured text format optimized for manual editing.

### CSV Export

**CSV export** via `exportAsCSV()` produces three separate tables: entity types, relationships, and properties. This tabular format facilitates spreadsheet editing and rapid data inspection for ontology review sessions.

## How Import Detection and Serialization Work

The import process uses `FileReader` to process file contents asynchronously. The following simplified example from [`ImportExportModal.tsx`](https://github.com/microsoft/Ontology-Playground/blob/main/ImportExportModal.tsx) demonstrates how the application detects RDF files and parses them accordingly:

```tsx
// Inside ImportExportModal.tsx – handleFileSelect
const reader = new FileReader();
reader.onload = (ev) => {
  const content = ev.target?.result as string;
  const fileName = file.name.toLowerCase();

  // Detect RDF/OWL by extension or XML start tag
  const isRdf = fileName.endsWith('.rdf') || fileName.endsWith('.owl') || fileName.endsWith('.iq')
                || content.trimStart().startsWith('<?xml') || content.trimStart().startsWith('<rdf:RDF');

  let ontology: Ontology;
  let bindings: DataBinding[] = [];

  if (isRdf) {
    const result = parseRDF(content);          // ← RDF parser returns ontology + bindings
    ontology = result.ontology;
    bindings = result.bindings;
  } else if (LEGACY_FORMATS_ENABLED) {
    const parsed = JSON.parse(content);         // ← legacy JSON format
    ontology = parsed.ontology;
    bindings = parsed.bindings || [];
  } else {
    throw new Error('Unsupported file format');
  }

  loadOntology(ontology, bindings);             // ← store update
};
reader.readAsText(file);

```

For RDF export, the application leverages the dedicated serializer:

```tsx
// Inside ImportExportModal.tsx – handleExport
if (exportFormat === 'rdf') {
  const rdf = serializeToRDF(currentOntology, dataBindings); // ← serializer.ts
  download(rdf, `${currentOntology.name}-ontology.rdf`, 'application/rdf+xml');
}

```

The YAML export constructs the format through string templating:

```tsx
// Inside ImportExportModal.tsx – exportAsYAML()
const yaml = `
ontology:
  name: "${currentOntology.name}"
  description: "${currentOntology.description || ''}"
  entityTypes:
${currentOntology.entityTypes.map(e => `
  - id: "${e.id}"
    name: "${e.name}"
    description: "${e.description || ''}"
    icon: "${e.icon}"
    color: "${e.color}"
    properties:
${e.properties.map(p => `
      - name: "${p.name}"
        type: "${p.type}"
        ${p.isIdentifier ? 'isIdentifier: true' : ''}`).join('')}`).join('')}
  relationships:
${currentOntology.relationships.map(r => `
  - id: "${r.id}"
    name: "${r.name}"
    from: "${r.from}"
    to: "${r.to}"
    cardinality: "${r.cardinality}"`).join('')}
${dataBindings.length ? `
bindings:
${dataBindings.map(b => `
  - entityTypeId: "${b.entityTypeId}"
    source: "${b.source}"`).join('')}` : ''}
`;
download(yaml, `${currentOntology.name}-ontology.yaml`, 'text/yaml');

```

## Summary

- Microsoft Ontology Playground imports **RDF/OWL** (`.rdf`, `.owl`, `.iq`) and optional **legacy JSON** when `VITE_ENABLE_LEGACY_FORMATS` is enabled.
- The **export pipeline** supports **JSON**, **RDF/XML**, **YAML**, and **CSV** formats through `handleExport()` in [`ImportExportModal.tsx`](https://github.com/microsoft/Ontology-Playground/blob/main/ImportExportModal.tsx).
- **RDF serialization** relies on `serializeToRDF()` in [`src/lib/rdf/serializer.ts`](https://github.com/microsoft/Ontology-Playground/blob/main/src/lib/rdf/serializer.ts) to generate standards-compliant OWL documents with proper namespace declarations.
- **YAML and CSV** exports are pure JavaScript implementations within the modal component, requiring no external libraries.
- The store's `exportOntology()` method in [`appStore.ts`](https://github.com/microsoft/Ontology-Playground/blob/main/appStore.ts) provides the raw JSON representation reused across multiple export handlers.

## Frequently Asked Questions

### What file extensions are supported for importing ontologies?

Microsoft Ontology Playground accepts `.rdf`, `.owl`, and `.iq` files for standard RDF/OWL imports. When the `VITE_ENABLE_LEGACY_FORMATS` environment variable is set to `true`, the application also accepts `.json` files using the legacy format parser.

### How does the application detect RDF files versus JSON files?

The detection logic in [`ImportExportModal.tsx`](https://github.com/microsoft/Ontology-Playground/blob/main/ImportExportModal.tsx) checks file extensions first, then examines the content for XML signatures such as `<?xml` or `<rdf:RDF` start tags. If neither XML patterns nor recognized RDF extensions are found, and legacy formats are enabled, the file is parsed as JSON.

### Can I export an ontology to multiple formats without re-importing?

Yes. The export functionality operates entirely on the in-memory state managed by [`appStore.ts`](https://github.com/microsoft/Ontology-Playground/blob/main/appStore.ts). You can export the current ontology to JSON, then immediately export the same data to RDF/XML or YAML without reloading the application or re-importing source files.

### Where is the RDF/XML serialization logic implemented?

The RDF/XML export logic resides in [`src/lib/rdf/serializer.ts`](https://github.com/microsoft/Ontology-Playground/blob/main/src/lib/rdf/serializer.ts) within the `serializeToRDF()` function. This utility generates proper XML headers, namespace declarations, and OWL-specific elements including classes, datatype properties, and object properties based on the current ontology structure.