mirror of
https://github.com/inspec/inspec
synced 2024-11-23 21:23:29 +00:00
9cfc86d2ab
Light formatting changes, change order of example and matchers, slight color changes Signed-off-by: hannah-radish <hmaddy@chef.io>
61 lines
1.4 KiB
Text
61 lines
1.4 KiB
Text
---
|
|
title: About the json Resource
|
|
---
|
|
|
|
# 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.
|
|
|
|
### 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
|
|
|
|
This InSpec audit resource has the following matchers. For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
|
|
|
### name
|
|
|
|
The `name` matcher tests the value of `name` as read from a JSON file versus the value declared in the test:
|
|
|
|
its('name') { should eq 'foo' }
|