New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

vite-plugin-validate-json

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-validate-json

A Vite plugin to validate a set of paths to JSON files.

latest
Source
npmnpm
Version
0.0.4
Version published
Weekly downloads
8
-11.11%
Maintainers
0
Weekly downloads
 
Created
Source

Vite Plugin Validate JSON

A Vite plugin that validates all JSON files in specified paths.

Features

  • ✅ Validate JSON syntax in your project
  • ✅ Check for duplicate keys in JSON files
  • ✅ Configurable paths with glob pattern support
  • ✅ Ability to ignore specific files
  • ✅ TypeScript support

Installation

npm install vite-plugin-validate-json --save-dev
# or
yarn add vite-plugin-validate-json --dev
# or
pnpm add -D vite-plugin-validate-json

Usage

Add the plugin to your vite.config.js or vite.config.ts:

import { defineConfig } from 'vite';
import { validateJsonPaths } from 'vite-plugin-validate-json';

export default defineConfig({
  plugins: [
    validateJsonPaths({
      paths: ['src/**/*.json', 'public/**/*.json'],
      allowDuplicateKeys: false, // default: false
      ignoreFiles: ['node_modules/**/*', 'dist/**/*'], // optional
    }),
    // other plugins...
  ],
});

Configuration Options

OptionTypeDefaultDescription
pathsstring[]-Glob patterns for JSON files to validate
allowDuplicateKeysbooleanfalseSet to true to allow duplicate keys in JSON files
ignoreFilesstring[][]Files to ignore during validation

How It Works

This plugin runs during the Vite build process and:

  • Finds all JSON files matching the specified glob patterns
  • Validates the JSON syntax of each file
  • Checks for duplicate keys (unless allowDuplicateKeys is set to true)
  • Throws an error if validation fails, stopping the build process

Example Error Messages

If a JSON file contains invalid syntax:

❌ Error while validating src/config.json with error SyntaxError: Unexpected token } in JSON at position 42

If a JSON file contains duplicate keys (and allowDuplicateKeys is false):

❌ Error while validating src/translations.json with error Error: Duplicate key: "welcome" at position 102

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Keywords

vite

FAQs

Package last updated on 12 Mar 2025

Did you know?

Socket

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.

Install

Related posts