Sha256: 5a22bcbe5e623e40c7740b997b3297de56a779dd1da7f6c0d0bf3714207f2eab

Contents?: true

Size: 1.33 KB

Versions: 41

Compression:

Stored size: 1.33 KB

Contents

---
title: About the json Resource
platform: os
---

# json

Use the `json` InSpec audit resource to test data in a JSON file.

<br>

## Syntax

A `json` resource block declares the data to be tested. Assume the following JSON file:

    {
      "name" : "hello",
      "meta" : {
        "creator" : "John Doe"
      },
      "array": [
        "zero",
        "one"
      ]
    }

This file can be queried using:

    describe json('/path/to/name.json') do
      its('name') { should eq 'hello' }
      its(['meta','creator']) { should eq 'John Doe' }
      its(['array', 1]) { should eq 'one' }
    end

where

* `name` is a configuration setting in a JSON file
* `should eq 'foo'` tests a value of `name` as read from a JSON file versus the value declared in the test

<br>

## Examples

The following examples show how to use this InSpec audit resource.

### name

The `name` matcher tests the value of the filename as read from a JSON file versus the value declared in the test:

    its('name') { should eq '/tmp/example.json' }

### Test a cookbook version in a policyfile.lock.json file

    describe json('policyfile.lock.json') do
      its(['cookbook_locks', 'omnibus', 'version']) { should eq('2.2.0') }
    end

<br>

## Matchers

For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
inspec-core-2.2.55 docs/resources/json.md.erb
inspec-2.2.55 docs/resources/json.md.erb
inspec-core-2.2.54 docs/resources/json.md.erb
inspec-2.2.54 docs/resources/json.md.erb
inspec-core-2.2.50 docs/resources/json.md.erb
inspec-2.2.50 docs/resources/json.md.erb
inspec-core-2.2.41 docs/resources/json.md.erb
inspec-2.2.41 docs/resources/json.md.erb
inspec-core-2.2.35 docs/resources/json.md.erb
inspec-2.2.35 docs/resources/json.md.erb
inspec-core-2.2.34 docs/resources/json.md.erb
inspec-2.2.34 docs/resources/json.md.erb
inspec-core-2.2.27 docs/resources/json.md.erb
inspec-2.2.27 docs/resources/json.md.erb
inspec-core-2.2.20 docs/resources/json.md.erb
inspec-2.2.20 docs/resources/json.md.erb
inspec-core-2.2.16 docs/resources/json.md.erb
inspec-2.2.16 docs/resources/json.md.erb
inspec-core-2.2.10 docs/resources/json.md.erb
inspec-2.2.10 docs/resources/json.md.erb