# The food object

> Where a food lives, its versions, and how its nutrition and portions are described.

Foods come from four libraries, and every food is pointed at by its `library` and `key`.

```json
{
  "library": "off",
  "key": "3017620422003",
  "version": 1,
  "name": "Nutella",
  "brand": "Ferrero",
  "barcode": "3017620422003",
  "data": {
    "base": "g",
    "nutrition": {
      "basisAmount": 100,
      "values": { "kcal": 539, "protein": 6.3, "carbs": 57.5, "fat": 30.9, "saturatedFat": 10.6, "sugars": 56.3, "salt": 0.11 }
    },
    "measures": [{ "label": "tablespoon", "size": 15 }],
    "defaultPortion": { "amount": 15, "unit": "g" }
  }
}
```

## Libraries

| Library | Holds |
| --- | --- |
| `mine` | Your own foods and recipes. Only you see them. |
| `composition` | Generic ingredients such as eggs or rice. |
| `splot` | Packaged products in the Splot database. |
| `off` | Packaged products from Open Food Facts. |

## Fields

| Field | Type | Description |
| --- | --- | --- |
| `library` | string | The library the food lives in. One of `off`, `splot`, `mine` or `composition`. |
| `key` | string | Its key in that library. Send `library` and `key` as `food` to log it. |
| `version` | integer | Foods change over time; meals and recipes keep the version they were saved with. |
| `name` | string | The food's name. |
| `brand` | string or null | The brand, for packaged products. |
| `barcode` | string or null | The barcode, for packaged products. |
| `data` | object | Nutrition, portions and recipe details. |

## Data

| Field | Type | Description |
| --- | --- | --- |
| `base` | string | The unit nutrition is given in. One of `g`, `ml` or `serving`. |
| `nutrition` | object | Nutrients for `basisAmount` of the base unit, such as per 100 g. A nutrient left out is unknown, not zero. |
| `measures` | array | Other portions by name, each `{ "label", "size" }` in the base unit, such as a tablespoon of 15 g. Up to 30 items. |
| `defaultPortion` | object | The usual portion, as `{ "amount", "unit" }`. |
| `composition` | string | Ingredients as printed on the label. Up to 10,000 characters. |
| `note` | string | Anything else worth knowing. Up to 10,000 characters. |
| `images` | array | Photos, as public links or saved Splot photos. Up to 20 items. |
| `recipe` | object | For a recipe: its `servings`, optional `minutes`, and `steps`. |
| `source` | object | Where the values come from, such as `{ "origin": "label" }`, or `estimate` with a `description`. |
| `ingredients` | array | For a recipe: its foods, each with a `portion`. |
| `thumbnail` | string | Optional public Storage path for a small food image. Read-only; omit when saving a food. |

A recipe's nutrition is added up from its ingredients, per serving. Each nutrient counts the ingredients that list it; one that none of them list is left out.
