# Schemas

JSON schemas for config, themes, teams etc.

## How to validate data from production database

1. Use the API to fetch the data. Example:

    ```shell
    $ curl -X GET "https://api.datawrapper.de/v3/admin/teams?limit=10000" \
           -H "Authorization:Bearer $AUTH_TOKEN" -o teams.json
    ```

2. Convert the data to [JSONL](https://jsonlines.org/) and optionally remove duplicate objects and
   compress it. Example:

    ```shell
    $ jq -r --indent 0 '.list[].settings' < teams.json | sort -u | gzip -c > teams.jsonl.gz
    ```

3. Use `scripts/validate-jsonl.js` to validate the JSONL file against one of our schemas. Example:

    ```shell
    $ zcat teams.jsonl.gz | scripts/validate-jsonl.js teamSettings > errors.jsonl
    1 is valid
    2 has problems
    ```

    The file `errors.jsonl` will now contain information about the objects whose validation failed:

    ```jsonl
    {"lineNumber":2,"errorMessage":"\"foo\" is not allowed","originalData":{"foo":"bar"}}
    ```
