Skip to content
A flexible JSON linter with out of the box support for OpenAPI v2 and v3
Branch: develop
Clone or download
marbemac and P0lip feat: add default resolvers (#245)
BREAKING CHANGE: json-ref-resolver upgraded to 2.x

* fix: Bump @stoplight/types from 5.1.2 to 7.0.1 (#224)

Bumps [@stoplight/types]( from 5.1.2 to 7.0.1.
- [Release notes](
- [Commits](stoplightio/types@v5.1.2...v7.0.1)

Signed-off-by: dependabot[bot] <>

* fix: upgrade ref resolver (#225)

* chore: Bump yaml from 1.5.1 to 1.6.0

Bumps [yaml]( from 1.5.1 to 1.6.0.
- [Release notes](
- [Commits](eemeli/yaml@v1.5.1...v1.6.0)

Signed-off-by: dependabot[bot] <>

* fix: invalid-ref error (#228)

* fix: handle ajv resolving issues

* feat: include resolver errors

* chore: [Security] Bump tar from 2.2.1 to 2.2.2

Bumps [tar]( from 2.2.1 to 2.2.2. **This update includes security fixes.**
- [Release notes](
- [Commits](npm/node-tar@v2.2.1...v2.2.2)

* chore: Bump @types/node from 12.0.2 to 12.0.3

Bumps [@types/node]( from 12.0.2 to 12.0.3.
- [Release notes](
- [Commits](

* chore: Bump typescript from 3.4.5 to 3.5.1

Bumps [typescript]( from 3.4.5 to 3.5.1.
- [Release notes](
- [Commits](

* chore: Bump @stoplight/types from 7.0.1 to 7.1.0

Bumps [@stoplight/types]( from 7.0.1 to 7.1.0.
- [Release notes](
- [Commits](stoplightio/types@v7.0.1...v7.1.0)

* chore: Bump @oclif/command from 1.5.13 to 1.5.14

Bumps [@oclif/command]( from 1.5.13 to 1.5.14.
- [Release notes](
- [Changelog](
- [Commits](oclif/command@v1.5.13...v1.5.14)

* chore: Bump @types/lodash from 4.14.130 to 4.14.133

Bumps [@types/lodash]( from 4.14.130 to 4.14.133.
- [Release notes](
- [Commits](

* feat: add default resolvers

* feat: support passing resolve option into run cmd

* test: fix them

* feat: resolve http and json refs in cli

* fix: use the resolved value in schema function

* fix: missing function call

* fix: use actual schema object

* test: update spectral.test.ts

* fix: do not try to resolve valid uris

* chore: rename authority to documentUri

* chore: use node-fetch

* fix: parse remote yaml in resolver

* chore: oops remove dummy fixture

* chore: use extname

* fix: resolve targetUri before run if its a file
Latest commit c1e0840 Jun 18, 2019

Spectral logo

Test Coverage Maintainability

A flexible JSON object linter with out of the box support for OpenAPI v2 and v3


  • Create custom rules to lint any JSON object
  • Use JSON paths to apply rules / functions to specific parts of your JSON objects
  • Built-in set of functions to help build custom rules. Functions include pattern checks, parameter checks, alphabetical ordering, a specified number of characters, provided keys are present in an object, etc
  • Create custom functions for advanced use cases
  • Optional ready to use rules and functions to validate and lint OpenAPI v2 and v3 documents
  • Validate JSON with Ajv


Local Installation

npm install @stoplight/spectral

Global Installation

npm install -g @stoplight/spectral

Supports Node v8.3+.

Executable binaries

For users without Node and/or NPM/Yarn, we provide standalone packages for all major platforms:

  • x64 Windows
  • x64 MacOS
  • x64 Linux

You can find them here. Once downloaded, you can proceed with the standard procedure for running any CLI tool.

./spectral-macos lint petstore.yaml

Note, the binaries are not auto-updatable, therefore you will need to download a new version on your own.

Installing binaries system-wide

sudo mv ./spectral-linux /usr/local/bin/spectral

You may need to restart your terminal. Now, spectral command will be accessible in your terminal.

Head over to releases for the latest binaries.


docker run --rm -it stoplight/spectral lint "${URL}"`



Spectral can be run via the command-line:

spectral lint petstore.yaml

Other options include:

  -c, --config=config          path to a config file
  -e, --encoding=encoding      text encoding to use
  -f, --format=json|stylish    formatter to use for outputting results
  -h, --help                   show CLI help
  -m, --maxResults=maxResults  deprecated: use --max-results instead
  -o, --output=output          output to a file instead of stdout
  -r, --ruleset=ruleset        path to a ruleset file (supports remote files)
  -s, --skip-rule=skip-rule    ignore certain rules if they are causing trouble
  -v, --verbose                increase verbosity
  --max-results=max-results    [default: all] maximum results to show

Note: The Spectral CLI supports both YAML and JSON.

Currently, the CLI supports validation of OpenAPI documents and lints them based on our default ruleset. It does not support custom rulesets at this time. Although if you want to build and run custom rulesets outside of the CLI, see Customization.


There are three key concepts in Spectral: Rulesets, Rules and Functions.

  • Ruleset is a container for a collection of rules and functions.
  • Rule filters your object down to a set of target values, and specify the function that should evaluate those values.
  • Function accept a value and return issue(s) if the value is incorrect.

Think of a set of rules and functions as a flexible and customizable style guide for your JSON objects.

Programmatic usage

Spectral is written in TypeScript (JavaScript) and can be used directly for when you need to use Spectral programatically. Take a look at our "JavaScript API documentation".


You can find all about rulesets here.


How is this different than Ajv?

Ajv is a JSON Schema validator, not a linter. Spectral does expose a schema function that you can use in your rules to validate all or part of the target object with JSON Schema (Ajv is used under the hood). However, Spectral also provides a number of other functions and utilities that you can use to build up a linting ruleset to validates things that JSON Schema is not well suited for.

I want to lint my OpenAPI documents but don't want to implement Spectral right now.

No problem! A hosted version of Spectral comes free with the Stoplight platform. Sign up for a free account here.

What is the difference between Spectral and Speccy?

With Spectral, lint rules can be applied to any JSON object. Speccy is designed to work with OpenAPI v3 only. The rule structure is different between the two. Spectral uses JSONPath path parameters instead of the object parameters (which are OpenAPI specific). Rules are also more clearly defined (thanks to TypeScript typings) and now require specifying a type parameter. Some rule types have been enhanced to be a little more flexible along with being able to create your own rules based on the built-in and custom functions.


If you are interested in contributing to Spectral itself, check out our contributing docs to get started.

Also, most of the interesting projects are built with Spectral. Please consider using Spectral in a project or contribute to an existing one.

If you are using Spectral in your project and want to be listed in the examples section, we encourage you to open an issue.

Example Implementations

Helpful Links

  • JSONPath Online Evaluator, a helpful tool to determine what path you want
  • stoplightio/json, a library of useful functions for when working with JSON
  • stoplightio/yaml, a library of useful functions for when working with YAML, including parsing YAML into JSON, and a few helper functions such as getJsonPathForPosition or getLocationForJsonPath

Thanks :)


If you have a bug or feature request, please open an issue here.

If you need help using Spectral or have a support question, please use the Stoplight Community forum. We've created an open source category for these questions. It's also a great place to share your implementations.

If you want to discuss something in private, you can reach out to Stoplight support at

You can’t perform that action at this time.