Parse a JSON string in Puppet
json, puppet
Solution
You would write:
$hash = loadjson('/tmp/file.json')
$message = $hash['output']['message']
$return_value = $hash['output']['return_value']
notice("$message, $return_value")
Or more concisely:
$hash = loadjson('/tmp/file.json')
[$message, $return_value] = $hash['output']
notice("$message, $return_value")
As mentioned in a comment above, there is no actual need for `include stdlib` here.
Problem
I am trying to parse a very simple json file in Puppet manifest but am struggling with it. Following sample Puppet manifest works but it only prints the entries in the json file ``` include stdlib $hash = loadjson('/tmp/file.json') notify("$hash") ``` JSON file ``` { "output": { "message": "This is the entire value", "return_value": "0" } } ``` I want to be able to assign "message" to variable "$message" and "return_value" to variable "$return_value"