Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
har-validator
Advanced tools
The har-validator npm package is a library designed to validate HTTP Archive (HAR) files. HAR files are JSON-formatted archives that track all the logging of a web browser's interaction with a site. This package ensures that HAR files adhere to the specification and structure expected, making it useful for developers working with web performance and debugging, API testing, and network monitoring.
HAR file validation
This feature allows developers to validate HAR files against the HAR format specification. The code sample demonstrates how to use the har-validator package to validate a HAR file. If the file is valid, it logs a success message; otherwise, it catches and logs the validation error.
const HARValidator = require('har-validator');
async function validateHAR(harData) {
try {
const valid = await HARValidator.har(harData);
console.log('HAR is valid:', valid);
} catch (err) {
console.error('HAR validation error:', err.message);
}
}
Ajv is a fast JSON schema validator. While not specifically designed for HAR files, it can be used to validate any JSON structure against a schema, making it a versatile alternative for general JSON validation tasks. Compared to har-validator, Ajv requires you to define or have access to the JSON schema, offering more flexibility at the cost of requiring more setup for HAR validation.
Tiny Validator (tv4) is another JSON schema validator that supports asynchronous validation and v4 of the JSON Schema standard. Similar to Ajv, it can be used for validating various JSON formats, including HAR files, if the appropriate schema is provided. It's a bit simpler and smaller than Ajv, making it a good choice for projects with less complex validation needs or tighter size constraints.
Extremely fast HTTP Archive (HAR) validator using JSON Schema.
# to use in cli
npm install --global har-validator
# to use as a module
npm install --save har-validator
Usage: har-validator [options] <files ...>
Options:
-h, --help output usage information
-V, --version output the version number
-s, --schema [name] validate schema name (log, request, response, etc ...)
har-validator har.json
har-validator --schema request request.json
Returns true
or false
.
data: Object
(Required)
a full HAR object
callback: Function
gets two arguments (err, valid)
var HAR = require('./har.json');
var validate = require('har-validator');
validate(HAR, function (e, valid) {
if (e) console.log(e.errors)
if (valid) console.log('horray!');
});
Returns true
or false
.
data: Object
(Required)
a log object
callback: Function
gets two arguments (err, valid)
var validate = require('har-validator');
validate.log(data, function (e, valid) {
if (e) console.log(e.errors)
});
Returns true
or false
.
data: Object
(Required)
a cache object
callback: Function
gets two arguments (err, valid)
var validate = require('har-validator');
validate.cache(data, function (e, valid) {
if (e) console.log(e.errors)
});
Returns true
or false
.
data: Object
(Required)
a "beforeRequest" or "afterRequest" objects
callback: Function
gets two arguments (err, valid)
var validate = require('har-validator');
validate.cacheEntry(data, function (e, valid) {
if (e) console.log(e.errors)
});
Returns true
or false
.
data: Object
(Required)
a content object
callback: Function
gets two arguments (err, valid)
var validate = require('har-validator');
validate.content(data, function (e, valid) {
if (e) console.log(e.errors)
});
Returns true
or false
.
data: Object
(Required)
a cookie object
callback: Function
gets two arguments (err, valid)
var validate = require('har-validator');
validate.cookie(data, function (e, valid) {
if (e) console.log(e.errors)
});
Returns true
or false
.
data: Object
(Required)
a creator object
callback: Function
gets two arguments (err, valid)
var validate = require('har-validator');
validate.creator(data, function (e, valid) {
if (e) console.log(e.errors)
});
Returns true
or false
.
data: Object
(Required)
a entry object
callback: Function
gets two arguments (err, valid)
var validate = require('har-validator');
validate.entry(data, function (e, valid) {
if (e) console.log(e.errors)
});
alias of Validate(data [, callback])
Returns true
or false
.
data: Object
(Required)
a page object
callback: Function
gets two arguments (err, valid)
var validate = require('har-validator');
validate.page(data, function (e, valid) {
if (e) console.log(e.errors)
});
Returns true
or false
.
data: Object
(Required)
a pageTimings object
callback: Function
gets two arguments (err, valid)
var validate = require('har-validator');
validate.pageTimings(data, function (e, valid) {
if (e) console.log(e.errors)
});
Returns true
or false
.
data: Object
(Required)
a postData object
callback: Function
gets two arguments (err, valid)
var validate = require('har-validator');
validate.postData(data, function (e, valid) {
if (e) console.log(e.errors)
});
Returns true
or false
.
data: Object
(Required)
a record object
callback: Function
gets two arguments (err, valid)
var validate = require('har-validator');
validate.record(data, function (e, valid) {
if (e) console.log(e.errors)
});
Returns true
or false
.
data: Object
(Required)
a request object
callback: Function
gets two arguments (err, valid)
var validate = require('har-validator');
validate.request(data, function (e, valid) {
if (e) console.log(e.errors)
});
Returns true
or false
.
data: Object
(Required)
a response object
callback: Function
gets two arguments (err, valid)
var validate = require('har-validator');
validate.cacheEntry(data, function (e, valid) {
if (e) console.log(e.errors)
});
Returns true
or false
.
data: Object
(Required)
a timings object
callback: Function
gets two arguments (err, valid)
var validate = require('har-validator');
validate.timings(data, function (e, valid) {
if (e) console.log(e.errors)
});
Donations are welcome to help support the continuous development of this project.
FAQs
Extremely fast HTTP Archive (HAR) validator using JSON Schema
The npm package har-validator receives a total of 10,953,748 weekly downloads. As such, har-validator popularity was classified as popular.
We found that har-validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.