# Validate entities with JSON schemas

To validate entities when you're creating or updating your feed, use the following JSON
Schemas. The schemas are based on the [JSON Schema specification](https://json-schema.org).
By adding a unit test to validate the entities you generate, you can detect
issues that would impact the feed quality. You can also use these schemas during
the development of your feed to avoid common errors.

## Select a Media Actions schema

- [Video On Demand Schema](https://developers.google.com/actions/media/tools/schema_vod.json) validates `Movie`, `TVEpisode`, `TVSeries` and `TVSeason` entities.
- [Live TV Schema](https://developers.google.com/actions/media/tools/schema_livetv.json) validates `BroadcastEvent`, `BroadcastService`, `CableOrSatelliteService`, `Movie`, `Organization`, `SportsEvent`, `TelevisionChannel`, `TVEpisode`, `TVSeason` and `TVSeries` entities.
- [Music Schema](https://developers.google.com/actions/media/tools/schema_music.json) validates `MusicAlbum`, `MusicGroup`, `MusicPlaylist` and `MusicRecording` entities.
- [Radio Schema](https://developers.google.com/actions/media/tools/schema_radio.json) validates `RadioBroadcastService` entities.

> [!WARNING]
> **Warning:** The `TVSeries`, `TVSeason`, `TVEpisode` and `Movie` specifications differ between VOD and Live TV. Use the schema that corresponds to the intended use of the entity or use the VOD schema if the entity is used as VOD and Live TV.

Use the specification on this site as the source of truth, since these schemas may not have all the features implemented.

## Choose a validator

You can find the list of [validator implementations](https://json-schema.org/implementations.html#validators) on [json-schema.org](https://json-schema.org/).

The schemas provided are written in [draft 7](https://json-schema.org/specification.html), so the implementation you choose needs to support this version to work properly.

> [!WARNING]
> **Warning:** We can't endorse any implementation. It's your responsibility to choose from existing implementations, and to make sure it runs safely within your process.

## Example of validation

The following example show how to validate all entities present in a file
`feed.json` using the schema file `schema.json` and the [jsonschema](https://github.com/Julian/jsonschema) python module. The entities are in the
property `dataFeedElement` as specified in the [data feed envelope](https://developers.google.com/actions/media/reference#data_feed_envelope) documentation.


        import json
        from jsonschema import validate

        # Loading the schema file
        with open("schema.json", "r") as fp:
            schema = json.load(fp)

        # Opening the feed
        with open("feed.json", "r") as fp:
            feed = json.load(fp)

        # Validating each entity in the feed
        for entity in feed["dataFeedElement"] :
            try:
                validate(schema=schema, instance=entity)
                print("Entity validated successfully")
            except Exception as e:
                # e may contain an explanation as to why the entity wasn't valid
                print("Failed to validate the entity")