我正在尝试在 Puppet list 中解析一个非常简单的 json 文件,但我正在努力解决它。
以下示例 Puppet list 有效,但它仅打印 json 文件中的条目
include stdlib
$hash = loadjson('/tmp/file.json')
notify("$hash")
JSON 文件
{
"output": {
"message": "This is the entire value",
"return_value": "0"
}
}
我希望能够将“消息”分配给变量“$message”,将“return_value”分配给变量“$return_value”
最佳答案
你会写:
$hash = loadjson('/tmp/file.json')
$message = $hash['output']['message']
$return_value = $hash['output']['return_value']
notice("$message, $return_value")
或者更简洁:
$hash = loadjson('/tmp/file.json')
[$message, $return_value] = $hash['output']
notice("$message, $return_value")
正如上面评论中提到的,这里实际上不需要include stdlib
。
关于json - 在 Puppet 中解析 JSON 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43729915/