View definition
Every key of the JSON that defines a view.
On this page
A view is a JSON object that you write in the View specification editor. See Create a 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 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 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.
Example
{
"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 }
]
}