קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
כדי לאמת ישויות כשיוצרים או מעדכנים את הפיד, צריך להשתמש בסכימות ה-JSON הבאות. הסכימות מבוססות על מפרט JSON Schema.
הוספת בדיקת יחידה לאימות הישויות שאתם יוצרים מאפשרת לכם לזהות בעיות שעשויות להשפיע על איכות הפיד. אפשר גם להשתמש בסכימות האלה במהלך הפיתוח של הפיד כדי למנוע שגיאות נפוצות.
הסכימות שסופקו נכתבו בטיוטה 7, לכן כדי שההטמעה שתבחרו תפעל כמו שצריך, היא צריכה לתמוך בגרסה הזו.
דוגמה לאימות
בדוגמה הבאה מוסבר איך לאמת את כל הישויות שנמצאות בקובץ feed.json באמצעות קובץ הסכימה schema.json ומודול Python 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\")"]]