Although not commonly used as the primary backend for Hiera, JavaScript Object Notation (JSON) is also a backend option. JSON is generally not as readable as YAML. It is primarily meant to be easily parsed. An advantage of JSON is that it is widely used by web applications and can be easily generated. The JSON syntax can be verified using Node.js and the JSON.parse
JavaScript function.
Consider the following JSON code, which is stored in the example.json
file:
{ "books" : [ { "title":"Mastering Puppet" , "pages":"300" }, { "title":"Puppet Cookbook" , "pages":"250" }, { "title":"Troubleshooting Puppet" , "pages":"100" } ] }
We can parse the file with Node.js by using the JSON.parse
function. Install the Node.js binary.
Tip
Node.js is available at https://nodejs.org/. Node.js may be available via your system repositories. The package is named nodejs
on most distributions.
Run node
, as follows:
t@mylaptop ~ $ node >varfs = require('fs'); undefined >var file = fs.readFileSync('example...