Help:Tabular data - MediaWiki (original) (raw)

Languages:

Tabular data allows users to create CSV-like tables of data, and use them from other wikis to create automatic tables, lists, and graphs.

To create a new table, go to Wikimedia Commons, and create a new page in the Data namespace with a .tab suffix, such as Data:Sandbox/Name/Example.tab. Feel free to experiment by creating pages with the Sandbox/<username>/ prefix. For now, page content can only be edited in the raw JSON format and with a basic table editor, but a gadget allows import/export from/to CSV and Excel files.Another script allows import from existing graph wikitext. Generative AI can be prompted to import data from existing graph and table wikitext, and to update with new data. Eventually (written 21 November 2016), we hope there will be a spreadsheet-like editor to simplify data editing.

The underlying data format largely matches the Frictionless Data standard for a tabular data resource.

All data in the Data: namespace must explicitly indicate the license of the data. The recommended license is Public Domain, licensed under Creative Commons Zero (CC0) license. To indicate this, every data page must have "license": "CC0-1.0", which means the data can be used under the CC0 version 1.0, or (at your option) any later version. By editing the data, you agree to the Terms of Use, and you irrevocably agree to release your contribution to the public domain under CC0.

If it isn't possible to release the data under CC0, the following licenses are also supported:

Any templates that pull data from non-CC0 licensed datasets need to comply with the relevant attribution terms, hence it is highly encouraged to prefer CC0 whenever possible.

At some future time, the list of licenses supported by the Data namespace may be expanded.

Tabular JSON data supports several basic value types. You may also use null instead of the value to mark it as missing.

Tabular data has several required and optional top-level elements:

Name Required? Description
license Required must always be set to "CC0-1.0" string value. For now, tabular data only supports CC0 (Public Domain dedication) license version 1.0 or later. More license support may be available in the future.
schema: {"fields": [{...}, {...}, ...]} Required must set to an object that contains a list. Each field describes a column of the tabular data. Each field must be an object with mandatory "name" and "type" values. Name Required? Description name Required the name of the column. The value must begin with a letter or an underscore "_", and must only contain letters, underscores, or digits. This is done so that each header can be easily used from a coding environment like Lua or Vega graphs. type Required must be set to one of these values: "number", "boolean", "string", or "localized". title Optional an optional translation for the column's header. If set, it must be a localized string object.
data Required must always be set to a list of lists. Each sub-list must have the same number of elements as headers, and must match the value types.
description Optional must be set to a localized string value - an object with at least one key-value, where the key is a language code (e.g. "en"), and the value is a description string.
sources Optional must be a Wiki markup string value that describes the source of the data.
mediawikiCategories Optional must be set to a list that contains objects. Each object can have two values: Name Required? Description name Required name of a category the tabular data page itself should be added to. sort Optional what sort key to use for the page in the category.

There are two ways to use this data on-wiki:

On Commons, transcluding a page from the Data namespace, i.e. {{Data:Example.tab}}, will render it as an HTML table. To access data directly on a wiki page, you can import (if you don't already have them) the tabular data module (requires the navbar module) and optionally the tabular query template (requires the before mentioned tabular data module). With these tools you can easily get the value of a single cell.

{ "license": "CC0-1.0", "description": { "en": "Some good fruits for you", "es": "Algunas buenas frutas para ti" }, "sources": "http://example.com and [[a wiki page]]", "schema": { "fields": [ { "name": "id", "type": "string", "title": { "en": "Fruit ID", "fr": "ID de fruit" }}, { "name": "name", "type": "localized", "title": { "en": "Fruit name", "fr": "Nom de fruit" }}, { "name": "count", "type": "number", "title": { "en": "Count", "fr": "Décompte" }}, { "name": "like", "type": "boolean", "title": { "en": "Do I like it?", "fr": "L’aimes-tu ?" }}, { "name": "description", "type": "localized", "title": { "en": "Fruit description", "fr": "Description du fruit" }} ] }, "data": [ [ "peaches", { "en": "Peaches", "es": "Melocotones", "fr": "Pêches" }, 100, true, { "en": "Magnificent but a bit sweet", "es": "Magníficos pero un poco dulces", "fr": "Magnifiques mais un peu sucrées" } ], [ "apples", { "en": "Apples", "es": "Manzanas", "fr": "Pommes" }, 150, true, { "en": "Red, not green", "es": "Rojas, no verdes", "fr": "Rouges, pas vertes" } ] ], "mediawikiCategories": [ { "name": "Example category", "sort": "Its sortkey" }, { "name": "Example category 2" } ] }

See c:Data:COVID-19 cases in Santa Clara County, California.tab for an example of how JSON data renders on Commons.

There are several tools available for converting other formats to JSON

Considerations around Extension:Chart and Excel/Libreoffice Calc

[edit]

Many Excel sheets have many more columns than it makes sense to show in a diagram. Since June 2025, Extension:Chart supports graphing only select columns (curves).

Before that, to conveniently graph a subset of the curves, a version of the .tab page had to be produced with the corresponding subset of the columns.

The data can be exported from Commons as a CSV file, modified in a spreadsheet program, and then converted back to tabular JSON using c:MediaWiki talk:Gadget-TabularImportExport.js.