Forge Home

validate_json_schema

Puppet function for validating json against a json schema

8,053 downloads

8,053 latest version

5.0 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Version information

  • 0.0.1 (latest)
released Nov 27th 2015
This version is compatible with:
  • RedHat, Ubuntu, Debian, Fedora, CentOS

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'deanwilson-validate_json_schema', '0.0.1'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add deanwilson-validate_json_schema
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install deanwilson-validate_json_schema --version 0.0.1

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download

Documentation

deanwilson/validate_json_schema — version 0.0.1 Nov 27th 2015

puppet-validate_json_schema

A Puppet function to validate JSON against a JSON schema

Introduction

Sometimes ensuring that JSON is valid isn't enough. You could need to assert the presence of certain values and ensure they are specific types. In those cases validating your JSON against a schema can help prevent you deploying well formed but invalid JSON from Puppet.

validate_json_schema returns true if the supplied JSON validates against the provided schema and throws a Puppet::ParseError and halts the catalog run if it fails.

Examples

Ensure the json-schema gem is installed on the puppet master:

/opt/puppetlabs/server/bin/puppetserver gem install json-schema --no-ri --no-rdoc

Then restart your puppetmaster to pick up the new gem.

You can then use the function in your manifests:

class json_tester {

  $json_data   = file('json_tester/valid-json.json')
  $json_schema = file('json_tester/valid-schema.json')

  if validate_json_schema($json_data, $json_schema, true) {
    file { '/tmp/valid_json':
      content => $json_data,
    }
  }
}

If you supply invalid json you'll see an error like this on your clients

Error: Could not retrieve catalog from remote server:
Error 400 on SERVER: Evaluation Error: 
Error while evaluating a Function Call, Invalid JSON: ["The property
'#/elements' of type String did not match the following type:
integer in schema 5fe3442c-38ba-5365-a5ae-39a9c406c715#"] at /etc/p-
uppetlabs/code/environments/production/modules/json_tester/manifest-
s/init.pp:6:6 on node puppettester.example.com

License

Apache 2.0 - Dean Wilson