Skip to content

JSON File Validator

Actions

About

This action allows you to choose which JSON files will be validated and with which schema that is to occur
v1.1.4
Latest
Star (0)

jsv-action

An Action that validates any JSON files in your project against JSON schemas that are also in your project. This action uses the Ajv project to compile schemas and validate JSON using the 07 draft of the JSON schema.

This action currently doesn't support file globs; you must pair any JSON files against the schema you want to use for validation for each file.

You need to use the actions/checkout action so the validation code can read your JSON files.


Inputs

Rules

  1. The key-and-file list should always be equal to or longer than the key-and-schema list
  2. You can reference the same schema key in multiple key-and-file entries
  3. For each key, you must have at least one file and one schema

key-and-file

This input is a space-delimited string of keys and JSON files. The format is key:file, where the key is used to pair against the keys used in the key-and-schema input.

Example

- uses: ewilliams-zoot/jsv-action@v1
  with:
    key-and-file: 'user:files/json/user.json accounts:files/json/accounts.json'

key-and-schema

This input takes in the same format as the key-and-file input but references the JSON schemas you want to use to validate the JSON files in the key-and-file list.

Building on Example

- uses: ewilliams-zoot/jsv-action@v1
  with:
    key-and-file: 'user:files/json/user.json accounts:files/json/accounts.json'
    key-and-schema: 'user:files/schemas/user_schema.json accounts:files/schemas/account_schema.json'

Outputs

This action does not have any outputs.


Full Example

Note: you do not have to have your keys in the same order in both lists. The keys are added to a hashmap, so the order doesn't matter.

name: Validate My JSON
on: [push]
jobs:
  validate-json-files:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: ewilliams-zoot/jsv-action@v1
        with:
          key-and-file: 'users:users.json accounts:accounts.json'
          key-and-schema: 'accounts:account_schema.json users:user_schema.json'

Full Example With Multiple File Keys

Note how there are two files in the key-and-file list that reference the person key. If files share the same schema, you can save typing in the key-and-schema list. Hopefully soon I'll get to supporting globs to save even more typing.

name: Validate My JSON
on: [push]
jobs:
  validate-json-files:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: ewilliams-zoot/jsv-action@v1
        with:
          key-and-file: 'person:users.json person:black_list.json accounts:accounts.json'
          key-and-schema: 'person:person_schema.json accounts:account_schema.json'

JSON File Validator is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

This action allows you to choose which JSON files will be validated and with which schema that is to occur
v1.1.4
Latest

JSON File Validator is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.