피드를 만들거나 업데이트할 때 항목을 검증하려면 다음 JSON 스키마를 사용하세요. 스키마는 JSON 스키마 사양을 기반으로 합니다.
생성한 항목의 유효성을 검사하는 단위 테스트를 추가하면 피드 품질에 영향을 미치는 문제를 감지할 수 있습니다. 피드 개발 중에 이러한 스키마를 사용하여 일반적인 오류를 방지할 수도 있습니다.
미디어 작업 스키마 선택
VOD 스키마는 Movie, TVEpisode, TVSeries, TVSeason 항목을 검증합니다.
라이브 TV 스키마는 BroadcastEvent, BroadcastService, CableOrSatelliteService, Movie, Organization, SportsEvent, TelevisionChannel, TVEpisode, TVSeason, TVSeries 항목을 검증합니다.
음악 스키마는 MusicAlbum, MusicGroup, MusicPlaylist, MusicRecording 항목을 검증합니다.
제공된 스키마는 초안 7으로 작성되었으므로 선택한 구현이 이 버전을 지원해야 제대로 작동합니다.
유효성 검사의 예
다음 예에서는 스키마 파일 schema.json 및 jsonschema Python 모듈을 사용하여 feed.json 파일에 있는 모든 항목을 검증하는 방법을 보여줍니다. 항목은 데이터 피드 엔벨로프 문서에 지정된 대로 dataFeedElement 속성에 있습니다.
importjsonfromjsonschemaimportvalidate# Loading the schema filewithopen("schema.json","r")asfp:schema=json.load(fp)# Opening the feedwithopen("feed.json","r")asfp:feed=json.load(fp)# Validating each entity in the feedforentityinfeed["dataFeedElement"]:try:validate(schema=schema,instance=entity)print("Entity validated successfully")exceptExceptionase:# e may contain an explanation as to why the entity wasn't validprint("Failed to validate the entity")
[null,null,[],[[["\u003cp\u003eJSON Schemas are provided to validate entities when creating or updating your data feed, ensuring data quality and consistency.\u003c/p\u003e\n"],["\u003cp\u003eChoose the appropriate Media Actions schema (VOD, Live TV, Music, or Radio) based on the type of entities in your feed.\u003c/p\u003e\n"],["\u003cp\u003eSelect a validator implementation that supports JSON Schema draft 7 and integrate it into your workflow for automated validation.\u003c/p\u003e\n"],["\u003cp\u003eRefer to the specification on this site as the primary source of truth for entity requirements, as schemas may not include all features.\u003c/p\u003e\n"],["\u003cp\u003eUtilize the provided example code snippet to validate entities within your feed using the chosen schema and a compatible validator.\u003c/p\u003e\n"]]],["To validate feed entities, use the provided JSON Schemas, based on the JSON Schema specification, for different media types: Video On Demand, Live TV, Music, and Radio. Add unit tests for validation to detect issues and avoid errors during feed development. Choose a validator implementation supporting draft 7, such as the `jsonschema` python module. Validate entities by loading the schema and feed, then iterating through entities in the `dataFeedElement` property and testing with the selected implementation, printing the results.\n"],null,["# Validate entities with JSON schemas\n\nTo validate entities when you're creating or updating your feed, use the following JSON\nSchemas. The schemas are based on the [JSON Schema specification](https://json-schema.org).\nBy adding a unit test to validate the entities you generate, you can detect\nissues that would impact the feed quality. You can also use these schemas during\nthe development of your feed to avoid common errors.\n\nSelect a Media Actions schema\n-----------------------------\n\n- [Video On Demand Schema](./schema_vod.json) validates `Movie`, `TVEpisode`, `TVSeries` and `TVSeason` entities.\n- [Live TV Schema](./schema_livetv.json) validates `BroadcastEvent`, `BroadcastService`, `CableOrSatelliteService`, `Movie`, `Organization`, `SportsEvent`, `TelevisionChannel`, `TVEpisode`, `TVSeason` and `TVSeries` entities.\n- [Music Schema](./schema_music.json) validates `MusicAlbum`, `MusicGroup`, `MusicPlaylist` and `MusicRecording` entities.\n- [Radio Schema](./schema_radio.json) validates `RadioBroadcastService` entities.\n\n| **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.\n\nUse the specification on this site as the source of truth, since these schemas may not have all the features implemented.\n\nChoose a validator\n------------------\n\nYou can find the list of [validator implementations](https://json-schema.org/implementations.html#validators) on [json-schema.org](https://json-schema.org/).\n\nThe 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.\n| **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.\n\nExample of validation\n---------------------\n\nThe following example show how to validate all entities present in a file\n`feed.json` using the schema file `schema.json` and the [jsonschema](https://github.com/Julian/jsonschema) python module. The entities are in the\nproperty `dataFeedElement` as specified in the [data feed envelope](../reference#data_feed_envelope) documentation. \n\n\n import json\n from jsonschema import validate\n\n # Loading the schema file\n with open(\"schema.json\", \"r\") as fp:\n schema = json.load(fp)\n\n # Opening the feed\n with open(\"feed.json\", \"r\") as fp:\n feed = json.load(fp)\n\n # Validating each entity in the feed\n for entity in feed[\"dataFeedElement\"] :\n try:\n validate(schema=schema, instance=entity)\n print(\"Entity validated successfully\")\n except Exception as e:\n # e may contain an explanation as to why the entity wasn't valid\n print(\"Failed to validate the entity\")"]]