Registry / serialization / har-schema

har-schema

JSON →
library2.0.0jsnpmunverified

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.

npm install har-schema
INSTALL
IMPORT
SIG · HAR-SCHEMA
H
har-schema
serializationjavascriptv2.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

harSchema
import harSchemas from 'har-schema'; const harSchema = harSchemas.har;
import { har } from 'har-schema';
The package exports an object containing all individual HAR schemas as properties. Access the top-level 'har' schema via `harSchemas.har`.
allSchemas
import allSchemas from 'har-schema';
const allSchemas = require('har-schema').default;
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.
RequestSchema
import allSchemas from 'har-schema'; const requestSchema = allSchemas.request;
import { RequestSchema } from 'har-schema';
Individual component schemas like `request` or `response` are properties of the default export object, not named exports.

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.

import allSchemas from 'har-schema'; import Ajv from 'ajv'; const ajv = new Ajv({ allErrors: true, messages: true }); // Initialize AJV validator const validate = ajv.compile(allSchemas.har); // Compile the main HAR schema const minimalHar = { log: { version: '1.2', creator: { name: 'HAR Schema Example', version: '1.0' }, entries: [] } }; const invalidHar = { log: { version: '1.2', creator: { name: 'HAR Schema Example' } // Missing 'version' in creator } }; // Validate a minimal, valid HAR object const isValidMinimal = validate(minimalHar); console.log('Minimal HAR is valid:', isValidMinimal); // Expected: true // Validate an invalid HAR object const isValidInvalid = validate(invalidHar); console.log('Invalid HAR is valid:', isValidInvalid); // Expected: false if (!isValidInvalid) { console.log('Validation errors:', ajv.errors); // Expected output will show 'creator' missing 'version' and 'entries' missing } /* Example of accessing an individual schema */ const validateRequest = ajv.compile(allSchemas.request); const request = { method: 'GET', url: 'http://example.com', httpVersion: 'HTTP/1.1', headers: [], queryString: [], cookies: [], headersSize: -1, bodySize: -1 }; console.log('Request schema validation:', validateRequest(request)); // Expected: true
Debug
Known issues
breakingVersion 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.
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.
affects: >=2.0.0
gotchaThe `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.
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.
affects: >=2.0.0
gotchaThis 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.
fix
Install a compatible JSON Schema validation library (e.g., `npm install ajv`) and use it in conjunction with `har-schema` to perform validation.
affects: *
Errors
Common errors & fixes
Cannot find module 'har-schema'
The package was not installed or is not correctly resolved by your module system.
fix
Run `npm install har-schema` or `yarn add har-schema` in your project directory.
Schema is invalid: data.schema should be object
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.
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.
Property 'har' does not exist on type 'typeof import("har-schema")'.
This TypeScript error occurs when trying to access `harSchema.har` (or similar) if TypeScript cannot correctly infer the structure of the default export.
fix
Ensure your `tsconfig.json` has `"esModuleInterop": true` and `"allowSyntheticDefaultImports": true`. If using `require`, ensure you're accessing `require('har-schema').har`.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
har-schema — npm install har-schema · libregistry