Schema 🔗

Each dataset has a schema/ endpoint providing access to definitions of the schema variables in the dataset. A schema variable is one actually populated with source data, in contrast to a derived variable whose values are calculated from other schema or derived variables via an expression.

The schema/ endpoint supports only the GET method and takes no parameters. Any user with view permissions on the dataset can access this method.

GET 🔗

The return value is a JSON crunch:table object.

  • The crunch:table contains a "metadata": object describing the schema variables.
  • Variable and subvariable definitions in the crunch:table are keyed by alias, making the crunch:table suitable for import with a CSV data file to create a new dataset.
  • The crunch:table response contains no "data": object.
  • Array variables (categorical-array and multiple-response) appear with consolidated subvariable definitions. Subvariable ordering corresponds to the position of each subvariables in the list.
  • Only variables visible to the requesting user appear in the response.
{
  "self": "https://alpha.crunch.io/api/datasets/:id/table/",
  "element": "crunch:table",
  "description": "Dataset Schema",
  "metadata": {
    "registered": {
      "alias": "registered",
      "type": "categorical",
      "name": "mymrset | Response #1",
      "categories": [
        {"numeric_value": 1, "selected": true, "id": 1, "name": "1", "missing": false},
        {"numeric_value": 0, "id": 0, "name": "0", "missing": false},
        {"numeric_value": null, "id": -1, "name": "No Data", "missing": true}
      ],
      "description": "bool1"
    },
    "string_var": {
      "alias": "string_var",
      "type": "text",
      "name": "str",
      "missing_reasons": {"No Data": -1},
      "description": "40 character string"
    },
    "cat_with_numval": {
      "alias": "cat_with_numval",
      "type": "categorical",
      "name": "x",
      "categories": [
        {"numeric_value": 1, "id": 1, "name": "red", "missing": false},
        {"numeric_value": 2, "id": 2, "name": "green", "missing": false},
        {"numeric_value": 3, "id": 3, "name": "blue", "missing": false},
        {"numeric_value": 4, "id": 4, "name": "4", "missing": false},
        {"numeric_value": 8, "id": 8, "name": "8", "missing": true},
        {"numeric_value": 9, "id": 9, "name": "9", "missing": false},
        {"numeric_value": null, "id": -1, "name": "No Data", "missing": true}
      ],
      "description": "Numeric variable with value labels"
    },
    "date_var": {
      "alias": "date_var",
      "name": "y",
      "type": "datetime",
      "missing_reasons": {"No Data": -1},
      "resolution": "s",
      "description": "Date variable"
    },
    "cat_array": {
      "alias": "cat_array",
      "name": "categorical_array",
      "description": "Sequence of categorical responses sharing same categories",
      "type": "categorical_array",
      "categories": [
        {"numeric_value": null, "selected": false, "id": 1, "missing": false, "name": "a"},
        {"numeric_value": null, "selected": false, "id": 2, "missing": false, "name": "b"},
        {"numeric_value": null, "selected": false, "id": 3, "missing": false, "name": "c"},
        {"numeric_value": null, "selected": false, "id": 4, "missing": false, "name": "d"},
        {"numeric_value": null, "selected": false, "id": -1, "missing": true, "name": "No Data"}
      ],
      "subvariables": [
        {"alias": "ca_subvar_2", "name": "CA Subvariable 2", "description": ""},
        {"alias": "ca_subvar_3", "name": "CA Subvariable 3", "description": ""},
        {"alias": "ca_subvar_1", "name": "CA Subvariable 1", "description": ""}
      ]
    }
  }
}
GET /datasets/:id/schema/ HTTP/1.1