如何定义含指定4个部门任务结构的合规JSON Schema?
JSON Schema for Task Department Structure
Hey there! Let's build the JSON Schema you're looking for, aligned perfectly with your requirements and sample data. First, quick note: I spotted a typo in your sample (taks should be task)—I'll make sure the schema uses the correct property name.
Key Requirements We'll Enforce
- The root object must include a
taskproperty of type object - The
taskobject can only contain four required array properties:development,review,production,distribution(no extra properties allowed) - Each department array holds identical task detail objects, with all the fields from your sample
Complete JSON Schema
{ "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "required": ["task"], "properties": { "task": { "type": "object", "required": ["development", "review", "production", "distribution"], "additionalProperties": false, "properties": { "development": { "type": "array", "items": { "type": "object", "required": ["description", "assigned_to", "start_date", "end_date", "status", "priority"], "properties": { "description": { "type": "string" }, "assigned_to": { "type": "string" }, "start_date": { "type": "string" }, "end_date": { "type": "string" }, "status": { "type": "string", "enum": ["wip", "complete", "OnHold"] }, "priority": { "type": "string", "enum": ["normal", "high", "low"] } }, "additionalProperties": false } }, "review": { "$ref": "#/properties/task/properties/development" }, "production": { "$ref": "#/properties/task/properties/development" }, "distribution": { "$ref": "#/properties/task/properties/development" } } } }, "additionalProperties": false }
Schema Breakdown
Let's walk through what this does:
- Root Level: Ensures only the
taskproperty exists at the root (viaadditionalProperties: false) and that it's required. - Task Object: Uses
additionalProperties: falseto strictly limit the allowed properties to the four departments—no extra ones can be added. All four departments are marked as required, so they'll always be present (even if their arrays are empty). - Task Detail Objects:
- All fields from your sample are marked as required, so every task must have them.
- I added
enumvalues forstatusandprioritybased on your sample data to restrict valid inputs to the values you're using. If you need to allow more values later, you can just update the enum lists. additionalProperties: falseon the task object ensures no extra fields can be added to individual tasks.
- Reusable Task Array: Instead of repeating the task object schema for each department, we use
$refto point to thedevelopmentschema—this keeps the code DRY and makes updates easier.
This schema will validate your sample data (once you fix the taks typo) and enforce all your requirements strictly.
内容的提问来源于stack exchange,提问作者Ruchit
相关产品推荐
相关产品推荐

