---
title: View definition
project: OpenReports
version: 1.0
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/openreports/1-0/reference/view-definition/
updated: 2026-11-19T07:46:46.798Z
---

# View definition

> Every key of the JSON that defines a view.

A view is a JSON object that you write in the **View specification** editor. See [Create a view](../../guides/create-view/).

## View keys

| Key | Required | What it does |
|---|---|---|
| `id` | Yes | A unique ID, for example `orders`. A view with the same `id` replaces the old one. |
| `name` | Yes | The name in the **Views** screen and in the **View** list of reports. |
| `sql` | Yes | A PostgreSQL `SELECT` that returns the data. |
| `fields` | Yes | The fields people can use, as a list of objects (below). |

## Field keys

| Key | Required | What it does |
|---|---|---|
| `column` | Yes | A column returned by `sql`. |
| `name` | Yes | The name people see in reports and column headers. |
| `type` | Yes | `string`, `number`, `boolean` or `date`. It decides the [filter types](../filter-types/) and how values show. |
| `group` | No | `true` lets reports group by this field. |
| `format` | No | For `number` fields: the number of decimals to show, for example `2`. |
| `output` | No | The ID of the field in reports and in the API. `"@"` uses the column name. Without it, OpenReports makes an ID from the column, such as `xfu9n6e`. |

## Field IDs

Reports and the [API](../api-list-reports/) refer to fields by their ID. Set `output` when you want readable IDs in the API, or when you may rename the column later: the ID then stays the same. See [Edit and remove views](../../guides/edit-views/).

## Example

```json
{
	"id": "orders",
	"name": "Orders",
	"sql": "SELECT customer, country, total, dtcreated FROM demo_orders",
	"fields": [
		{ "column": "customer", "name": "Customer", "type": "string", "group": true },
		{ "column": "country", "name": "Country", "type": "string", "group": true },
		{ "output": "total", "column": "total", "name": "Total", "type": "number", "format": 2 },
		{ "column": "dtcreated", "name": "Created", "type": "date", "group": true }
	]
}
```
