CSV, JSON and XML
Show CSV and TSV tables of up to a million rows, JSON as a collapsible tree and XML with highlighting, in React and in the browser.
CSV and TSV
Our own RFC 4180 parser handles quoted fields, embedded newlines and the delimiter (comma, semicolon, tab or pipe), which is detected from the file. Tables over 1,000 rows are windowed: rows are drawn near the view, column widths are fixed, the header stays put, and search covers every row. Up to a million rows open.
JSON
A collapsible tree of objects and arrays. Search finds keys and values.
XML
Shown as highlighted code. SVG files are shown as images, and Office and OpenDocument files (which are ZIP files of XML) get their own renderers.
Controller
| State | For CSV, TSV, JSON and XML |
|---|---|
page, pageCount | No pages: page is undefined and pageCount is 0. |
zoom, scale | Number zooms scale the table, tree or text; fit modes do not apply. |
outline, thumbnails | None. |
search.count | CSV: every cell of every row, including rows not drawn yet in large files. JSON: keys and values. |
progress | Worth showing for large files: a 5 MB CSV over a slow connection takes a while. |
can | zoom, search, print, download. |
Things to know:
- The delimiter and header-row controls are drawn in the surface, above the table.
- Files of 512 KB and up are parsed in a Web Worker;
statusis'ready'while parsing finishes, and the surface shows progress.
Headless
A data viewer with a download progress bar, search over all rows, text size and download:
'use client';
// A CSV / TSV / JSON viewer: a loading bar while the file downloads, search with match
// navigation, zoom, and download. Tables have no pages, so pageCount is 0.
import { useState } from 'react';
import { DocumentSurface, formatBytes, useDocViewer, useDocumentSearch, type DocSource } from '@openpreview/react';
import '@openpreview/react/styles.css';
export default function DataViewer({ source }: { source: DocSource }) {
const viewer = useDocViewer({ source });
const [query, setQuery] = useState('');
const results = useDocumentSearch(viewer, query);
const { loaded, total } = viewer.progress;
return (
<div className="flex h-full flex-col text-sm">
<header className="flex flex-wrap items-center gap-3 border-b p-2">
<strong>{viewer.fileName}</strong>
{viewer.detection && <span className="uppercase opacity-70">{viewer.detection.ext}</span>}
{viewer.status === 'loading' && (
<progress max={total ?? 1} value={total ? loaded : undefined}>
{formatBytes(loaded)}
</progress>
)}
<input className="rounded border px-2" placeholder="Search all rows" value={query} onChange={(e) => setQuery(e.target.value)} />
{query && (
<span>
{results.current + 1} / {results.count} <button onClick={results.prev}>↑</button> <button onClick={results.next}>↓</button>
</span>
)}
<span className="ml-auto">
<button onClick={viewer.zoomOut}>A−</button> <button onClick={viewer.zoomIn}>A+</button>
</span>
<button onClick={viewer.download}>Download</button>
</header>
<DocumentSurface viewer={viewer} className="min-h-0 flex-1" />
</div>
);
}OpenDocument (ODT, ODS, ODP)
Show LibreOffice and OpenOffice files (ODT text, ODS spreadsheets, ODP presentations) in React, drawn by the same engines as Word, Excel and PowerPoint.
Markdown, code and notebooks
Show Markdown, source code in 200+ languages, plain text, huge logs and Jupyter notebooks in React, with highlighting, search and printing.