# Record Syntax

### JSON Format

A single record may be encoded as a JSON object:

| Property | Value |
|-|-|
| <field name / label> | field type appropriate value / `null` |
| `"expressions"` | JSON object mapping field name/label to [expression](expression-syntax) |
| `"file"` | [binary object](binary-objects) (if database has `file` enabled) |
| `"tags"` | JSON array of string(s) (if database has `tag` enabled) |

The `"expressions"` property allows field values to be specified by expression, rather than explicit value. Between the base object and `"expressions"` object, field may only have a single value provided, or an error will be thrown.

Multiple records may be encoded as a JSON array of JSON objects in this format.

### DSV Format

Record data may be provided in a delimiter separated values format. In this case the record data itself is contained in a [binary object](binary-objects).

| Property | Value |
|-|-|
| `"type"` | `"dsv"`, `"csv"`, or `"tsv"`
| `"file"` | [binary object](binary-objects)
| `"delimiter"` | string (required for `"dsv"`)
| `"quote"` | string (optional)

The `"csv"` and `"tsv"` types specify default delimiters of comma (`,`) and tab (`\t`), respectively.

_Example_

```json
{
 "records": {
  "type": "dsv",
  "file" : "<object ID>",
  "delimit": ";"
 }
}
```

The format of the separated values file is largely based on the [RFC 4180 standard](http://tools.ietf.org/html/rfc4180). The specific requirements are:

* lines must end with `LF` (`\n`) or `CR` `LF` (`\r\n`)
* line breaks cannot be used in values
* the default quote character is `"` (double quotes)
* any field _may_ be quoted by the quote character
* any field containing the delimiter must be quoted
* a quote character in a quoted value must be represented by two quote characters
* the first row must contain the names of each field
* blank lines with no data are ignored