Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Để xác thực các thực thể khi bạn tạo hoặc cập nhật nguồn cấp dữ liệu, hãy sử dụng các Giản đồ JSON sau. Các giản đồ này dựa trên thông số kỹ thuật của Giản đồ JSON.
Bằng cách thêm một bài kiểm thử đơn vị để xác thực các thực thể mà bạn tạo, bạn có thể phát hiện các vấn đề sẽ ảnh hưởng đến chất lượng nguồn cấp dữ liệu. Bạn cũng có thể sử dụng các giản đồ này trong quá trình phát triển nguồn cấp dữ liệu để tránh các lỗi thường gặp.
Giản đồ truyền hình trực tiếp xác thực các thực thể BroadcastEvent, BroadcastService, CableOrSatelliteService, Movie, Organization, SportsEvent, TelevisionChannel, TVEpisode, TVSeason và TVSeries.
Music Schema xác thực các thực thể MusicAlbum, MusicGroup, MusicPlaylist và MusicRecording.
Radio Schema xác thực các thực thể RadioBroadcastService.
Hãy sử dụng thông số kỹ thuật trên trang web này làm nguồn đáng tin cậy, vì các giản đồ này có thể chưa triển khai hết tất cả các tính năng.
Các giản đồ được cung cấp được viết bằng bản nháp 7, vì vậy, phương thức triển khai mà bạn chọn cần hỗ trợ phiên bản này để hoạt động đúng cách.
Ví dụ về quy trình xác thực
Ví dụ sau đây cho biết cách xác thực tất cả các thực thể có trong tệp feed.json bằng cách sử dụng tệp giản đồ schema.json và mô-đun python jsonschema. Các thực thể này nằm trong thuộc tính dataFeedElement như được chỉ định trong tài liệu về thư bao nguồn cấp dữ liệu.
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\")"]]