Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@bpmn-io/element-templates-validator

Package Overview
Dependencies
Maintainers
9
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bpmn-io/element-templates-validator

Validate element templates based on JSON Schema

latest
Source
npmnpm
Version
2.13.0
Version published
Weekly downloads
12K
2.28%
Maintainers
9
Weekly downloads
 
Created
Source

element-templates-validator

CI

Validate element templates based on JSON Schema.

Installation

npm i --save @bpmn-io/element-templates-validator

Usage

Given an example element template:

import { validate } from '@bpmn-io/element-templates-validator';

import sample from './test/fixtures/rpa-broken.json';

const {
  valid,
  errors
} = validate(sample);

if (!valid) {
  console.error('Invalid JSON detected:', errors);
}

This will print detailed information about errors inside the sample:

[
  {
    "keyword": "type",
    "dataPath": "",
    "schemaPath": "#/type",
    "params": {
      "type": "object"
    },
    "message": "must be object",
    "dataPointer": {
      "value": {
        "line": 0,
        "column": 0,
        "pos": 0
      },
      "valueEnd": {
        "line": 177,
        "column": 1,
        "pos": 4825
      }
    }
  }
  ...
]

You can also pass a stringified template to ensure that the dataPointers of the errors reflect the correct position in the original string.

import { validate } from '@bpmn-io/element-templates-validator';

import { readFileSync } from 'node:fs';

const sample = readFileSync('./test/fixtures/rpa-broken.json', 'utf-8');

const {
  valid,
  errors
} = validate(sample);

if (!valid) {
  console.error('Invalid JSON detected:', errors);
}

If a parsed JSON object is passed, the dataPointers will assume that the source template is formatted with JSON.stringify(template, null, 2).

It's also possible to validate multiple objects at once. In this case, the list of templates supports only objects, not strings.

import { validateAll } from '@bpmn-io/element-templates-validator';

import samples from './test/fixtures/multiple-errors.json';

const {
  valid,
  results
} = validateAll(samples);

if (!valid) {
  console.error('Invalid JSON objects detected:', results.filter(r => !r.valid));
}

License

MIT

Keywords

json-schema

FAQs

Package last updated on 18 Sep 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