# Standard.to_dict()

Convert the standard to a dictionary.

Usage

[Source](https://github.com/posit-dev/pointblank/blob/main/pointblank/standard.py#L1400-L1473)

``` python
Standard.to_dict()
```

This method gives the standard as plain Python data, ready to be written as JSON or stored in a configuration system. It's the structure that [`to_yaml()`](../reference/Standard.to_yaml.md#pointblank.Standard.to_yaml) writes, without the top-level `standard` key, and [`from_dict()`](../reference/Standard.from_dict.md#pointblank.Standard.from_dict) turns it back into a [Standard](../reference/Standard.md#pointblank.Standard).

The dictionary always has a `"name"` key, and the other fields are only included when they're set. Each step becomes a single-key mapping from the method's name to its arguments (as with [`Step.to_dict()`](../reference/Step.md#pointblank.Step.to_dict)), or just the method's name for a step without arguments (like `"rows_distinct"`), and the thresholds become a mapping of the levels that are set. Column selectors (like [`matches()`](../reference/matches.md#pointblank.matches)) and the `applies_to=` table selector become `{"python": <code>}` blocks with the code that makes them (e.g., `{"python": "pb.matches('email')"}`). That code is in the subset of Python that's read back without `allow_python=True`, so a standard with selectors can be shared as data.

## Returns

`dict[str, Any]`  
A dictionary representation of the standard.

## Examples

Let's convert a standard for the ID columns of the staging tables.

``` python
import pointblank as pb

id_standard = pb.Standard(
    name="staging-ids",
    version="1.2.0",
    owner="data-platform",
    steps=[pb.Step("col_vals_not_null", columns=pb.ends_with("_id"))],
    applies_to=pb.tbl_starts_with("stg_") - pb.tbl_ends_with("_tmp"),
    thresholds=pb.Thresholds(warning=1),
)

id_standard.to_dict()
```

    {'name': 'staging-ids',
     'version': '1.2.0',
     'owner': 'data-platform',
     'applies_to': {'python': "pb.tbl_starts_with('stg_') - pb.tbl_ends_with('_tmp')"},
     'steps': [{'col_vals_not_null': {'columns': {'python': "pb.ends_with('_id')"}}}],
     'thresholds': {'warning': 1}}

The selectors are written as the code that makes them, and the unset fields (like `consumers`) are left out. The dictionary converts directly to JSON with `json.dumps()`.
