{"id":16051,"library":"har-schema","title":"HAR JSON Schemas","description":"The `har-schema` package provides the official JSON Schema definitions for the HTTP Archive (HAR) format, enabling robust validation of HAR files. It encompasses schemas for all HAR entities, including `log`, `pages`, `entries`, `requests`, `responses`, and more. The current stable version, 2.0.0 (released in 2017), migrated its schemas to conform with JSON-Schema Draft-06, a significant breaking change from prior versions. This package is foundational for tools that process or validate HAR data, acting as a data source for schema definitions rather than an executable library. Its release cadence is effectively dormant, with no new feature development since 2017, reflecting the stability of the HAR 1.2 specification it implements. It differentiates itself by being the direct, standard representation of the HAR spec in JSON Schema, compatible with any generic JSON Schema validation library.","status":"abandoned","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/ahmadnassri/har-schema","tags":["javascript","har","http","archive","JSON","schema","JSON-schema"],"install":[{"cmd":"npm install har-schema","lang":"bash","label":"npm"},{"cmd":"yarn add har-schema","lang":"bash","label":"yarn"},{"cmd":"pnpm add har-schema","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports an object containing all individual HAR schemas as properties. Access the top-level 'har' schema via `harSchemas.har`.","wrong":"import { har } from 'har-schema';","symbol":"harSchema","correct":"import harSchemas from 'har-schema';\nconst harSchema = harSchemas.har;"},{"note":"This is the primary way to access all available HAR schemas (e.g., 'request', 'response', 'cookie', etc.) as properties of the imported object. CommonJS `require` works identically.","wrong":"const allSchemas = require('har-schema').default;","symbol":"allSchemas","correct":"import allSchemas from 'har-schema';"},{"note":"Individual component schemas like `request` or `response` are properties of the default export object, not named exports.","wrong":"import { RequestSchema } from 'har-schema';","symbol":"RequestSchema","correct":"import allSchemas from 'har-schema';\nconst requestSchema = allSchemas.request;"}],"quickstart":{"code":"import allSchemas from 'har-schema';\nimport Ajv from 'ajv';\n\nconst ajv = new Ajv({ allErrors: true, messages: true }); // Initialize AJV validator\nconst validate = ajv.compile(allSchemas.har); // Compile the main HAR schema\n\nconst minimalHar = {\n  log: {\n    version: '1.2',\n    creator: {\n      name: 'HAR Schema Example',\n      version: '1.0'\n    },\n    entries: []\n  }\n};\n\nconst invalidHar = {\n  log: {\n    version: '1.2',\n    creator: {\n      name: 'HAR Schema Example'\n    } // Missing 'version' in creator\n  }\n};\n\n// Validate a minimal, valid HAR object\nconst isValidMinimal = validate(minimalHar);\nconsole.log('Minimal HAR is valid:', isValidMinimal); // Expected: true\n\n// Validate an invalid HAR object\nconst isValidInvalid = validate(invalidHar);\nconsole.log('Invalid HAR is valid:', isValidInvalid); // Expected: false\nif (!isValidInvalid) {\n  console.log('Validation errors:', ajv.errors);\n  // Expected output will show 'creator' missing 'version' and 'entries' missing\n}\n\n/* Example of accessing an individual schema */\nconst validateRequest = ajv.compile(allSchemas.request);\nconst request = {\n  method: 'GET',\n  url: 'http://example.com',\n  httpVersion: 'HTTP/1.1',\n  headers: [],\n  queryString: [],\n  cookies: [],\n  headersSize: -1,\n  bodySize: -1\n};\nconsole.log('Request schema validation:', validateRequest(request)); // Expected: true\n","lang":"typescript","description":"This quickstart demonstrates how to import the HAR schema and use it with the AJV validation library to validate both a minimal valid HAR object and an intentionally invalid one. It also shows how to access and validate individual HAR component schemas."},"warnings":[{"fix":"Ensure your JSON Schema validator (e.g., Ajv) is configured to use Draft-06 or a compatible newer draft, or upgrade your validator library if it's too old.","message":"Version 2.0.0 migrated all schemas to JSON-Schema Draft-06. If you were using `har-schema` with a validator configured for an older draft (e.g., Draft-04 or Draft-05), you must update your validator's configuration to support Draft-06 or newer, or stick to `har-schema` v1.x.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Be aware of the project's inactive status. If your project requires validation against newer HAR specifications or the latest JSON Schema drafts, you may need to find an alternative or fork this repository.","message":"The `har-schema` package is effectively abandoned since its last update in 2017. While the HAR 1.2 specification is stable, there will be no updates for potential future HAR spec versions, new JSON Schema drafts, or bug fixes. Relying on this package for critical new development should be done with caution.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Install a compatible JSON Schema validation library (e.g., `npm install ajv`) and use it in conjunction with `har-schema` to perform validation.","message":"This package *only* provides the JSON Schema definitions. It does not include a HAR parser, validator, or any other utility functions. You must use a separate JSON Schema validation library (like `ajv` or `har-validator`) to utilize these schemas.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Run `npm install har-schema` or `yarn add har-schema` in your project directory.","cause":"The package was not installed or is not correctly resolved by your module system.","error":"Cannot find module 'har-schema'"},{"fix":"Ensure your validator is set up to correctly parse Draft-06 schemas. For AJV, initialize with `new Ajv()` which defaults to Draft-07 (compatible), or explicitly `new Ajv({ allErrors: true, messages: true, schemaId: 'id' })` for Draft-06 specific handling if needed.","cause":"This error typically indicates that your JSON Schema validator is configured for an incompatible JSON Schema draft or that the schema object itself is malformed. `har-schema` v2.x uses Draft-06.","error":"Schema is invalid: data.schema should be object"},{"fix":"Ensure your `tsconfig.json` has `\"esModuleInterop\": true` and `\"allowSyntheticDefaultImports\": true`. If using `require`, ensure you're accessing `require('har-schema').har`.","cause":"This TypeScript error occurs when trying to access `harSchema.har` (or similar) if TypeScript cannot correctly infer the structure of the default export.","error":"Property 'har' does not exist on type 'typeof import(\"har-schema\")'."}],"ecosystem":"npm"}