json utility makes it easier to read and write to JSON files within in your checks.
This utility expects an absolute path to a JSON file and returns an object with methods that help you read and write to any JSON file.
To get full type-safety on all returned methods you can pass a generic type to the json function.
exists
Returns a boolean value indicating whether or not the file exists on disk.
Example
get
Returns
Returns the contents of a JSON file as an object. If the file does not exist or is not valid JSON,undefined will be returned.
Example
contains
Parameters
Record<string, unknown>
required
An object to check against the JSON file’s contents.
Returns
Returns a boolean value indicating whether or not the object is a subset of the JSON file’s contents. If the file does not exist or is not valid JSON,false will be returned.
Example
set
Parameters
Record<string, unknown>
required
An object that will be used to overwrite the JSON file’s contents.
Example
merge
Parameters
Record<string, unknown>
required
An object that will be deeply merged with the JSON file’s contents.
Example
remove
Parameters
string
required
A lodash-style path object that will be used to determine which property to remove.