docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a utility that tracks and reports parent-child relationships in JSON Schema documents.
Create a tool that analyzes a JSON Schema and generates a report showing the hierarchical relationships between schema objects. For each schema object that has a parent, the report should include:
The root schema has no parent and should not be included in the report.
Your tool should accept a JSON Schema object as input.
Return an array of relationship objects, where each object contains:
path: JSON Pointer to the child schemaparentPath: JSON Pointer to the parent schemakeyword: The keyword containing this schemakey: The property name (string) or array index (number)Sort the results by path alphabetically.
Given this schema:
{
properties: {
user: {
type: 'object',
properties: {
name: { type: 'string' }
}
}
},
allOf: [
{ type: 'object' },
{ required: ['user'] }
]
}Expected output:
[
{
path: '/allOf/0',
parentPath: '',
keyword: 'allOf',
key: 0
},
{
path: '/allOf/1',
parentPath: '',
keyword: 'allOf',
key: 1
},
{
path: '/properties/user',
parentPath: '',
keyword: 'properties',
key: 'user'
},
{
path: '/properties/user/properties/name',
parentPath: '/properties/user',
keyword: 'properties',
key: 'name'
}
]/**
* Analyzes a JSON Schema and returns parent-child relationships.
*
* @param {object} schema - The JSON Schema to analyze
* @returns {Array<{path: string, parentPath: string, keyword: string, key: string|number}>}
* Array of relationship objects sorted by path
*/
function trackSchemaParents(schema) {
// IMPLEMENTATION HERE
}
module.exports = { trackSchemaParents };Provides JSON Schema traversal with parent tracking capabilities.