موجودیت ها را با طرحواره های JSON اعتبار سنجی کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
برای اعتبارسنجی نهادها هنگام ایجاد یا بهروزرسانی فید خود، از طرحوارههای JSON زیر استفاده کنید. طرحواره ها بر اساس مشخصات طرحواره JSON هستند. با افزودن یک تست واحد برای اعتبارسنجی موجودیت هایی که تولید می کنید، می توانید مشکلاتی را که بر کیفیت خوراک تأثیر می گذارد شناسایی کنید. همچنین می توانید از این طرحواره ها در طول توسعه فید خود استفاده کنید تا از خطاهای رایج جلوگیری کنید.
طرحی از اقدامات رسانه ای را انتخاب کنید
طرحواره ویدیوی درخواستی موجودیت های Movie ، TVEpisode ، TVSeries و TVSeason را تأیید می کند.
طرحواره تلویزیون زنده ، موجودیتهای BroadcastEvent ، BroadcastService ، CableOrSatelliteService ، Movie ، Organization ، SportsEvent ، TelevisionChannel ، TVEpisode ، TVSeason و TVSeries را تأیید میکند.
Music Schema موجودیتهای MusicAlbum ، MusicGroup ، MusicPlaylist و MusicRecording را تأیید میکند.
طرحواره رادیویی نهادهای RadioBroadcastService را تأیید می کند.
از مشخصات موجود در این سایت به عنوان منبع حقیقت استفاده کنید، زیرا ممکن است این طرحواره ها همه ویژگی های اجرا شده را نداشته باشند.
طرحواره های ارائه شده در پیش نویس 7 نوشته شده اند، بنابراین پیاده سازی که انتخاب می کنید باید از این نسخه پشتیبانی کند تا به درستی کار کند.
نمونه ای از اعتبار سنجی
مثال زیر نشان می دهد که چگونه می توان تمام موجودیت های موجود در یک فایل feed.json را با استفاده از فایل طرحواره schema.json و ماژول پایتون jsonschema اعتبارسنجی کرد. موجودیت ها همانطور که در اسناد پاکت خوراک داده مشخص شده است در 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\")"]]