HAR JSON Schemas

2.0.0 · abandoned · verified Tue Apr 21

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.

Common errors

Warnings

Install

Imports

Quickstart

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

view raw JSON →