> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pysquirrels.com/llms.txt
> Use this file to discover all available pages before exploring further.

# DatasetMetadata

> Return type representing metadata about a dataset

Class representing metadata about a dataset including schema information.

Instances of `DatasetMetadata` are created by Squirrels when describing datasets (and as the base for `DatasetResult`); you should not construct this class directly.

If `DatasetMetadata` is needed for type annotation, it can be imported from the `squirrels.types` or `squirrels` module.

## Methods

### to\_json()

Returns the dataset metadata as a JSON-serializable dictionary.

```python theme={null}
def to_json(self) -> dict:
```

<ResponseField name="returns" type="dict">
  A dictionary containing dataset metadata with the following structure:

  <Expandable title="return structure">
    <ResponseField name="schema" type="object">
      Schema information for the dataset.

      <Expandable title="schema properties" defaultOpen>
        <ResponseField name="fields" type="array">
          Array of field objects, where each field has the following properties:

          <Expandable title="field properties" defaultOpen>
            <ResponseField name="name" type="string">
              The name of the field/column.
            </ResponseField>

            <ResponseField name="type" type="string">
              The data type of the field (e.g. "string", "integer", "float", "boolean", "date", "datetime").
            </ResponseField>

            <ResponseField name="condition" type="list[string]" default="[]">
              The condition(s) of when the field is included. Only used for documentation purposes.
            </ResponseField>

            <ResponseField name="description" type="string">
              Human-readable description of the field.
            </ResponseField>

            <ResponseField name="category" type="string">
              Category of the field (e.g. "dimension", "measure", "misc").
            </ResponseField>
          </Expandable>
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

## Examples

Here are some common usage patterns for the `DatasetMetadata` class. It is assumed that the code is running in an async context (e.g. inside an async function or a Jupyter Notebook cell).

### Get dataset metadata

```python theme={null}
from typing import TYPE_CHECKING
from squirrels import SquirrelsProject

if TYPE_CHECKING:
    from squirrels.types import DatasetMetadata

sqrl = SquirrelsProject()

# Get metadata for a dataset
metadata: "DatasetMetadata" = sqrl.dataset_metadata("sales_data")

# Access schema information as JSON
schema_json = metadata.to_json()
print(schema_json)
# Output: {'schema': {'fields': [{'name': 'date', 'type': 'date', ...}, ...]}}
```
