Ask Your Question

how to handle json data in puppet

asked 2016-11-28 12:21:55 -0600

updated 2016-11-28 13:55:21 -0600

I would like to know about the Json support in puppet.

In stdlib module there is a parse json function but i couldn't see any examples for using it.

I have a json file with the following format:


I would need to take the value (foobar) alone from the json file and assign it to a variable in puppet. how do i do that?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-11-29 06:30:14 -0600

Henrik Lindberg gravatar image

updated 2016-11-29 06:30:50 -0600

You can use the puppet file() function to read the json file into a String. Then you give that string to the parsejson() function. That returns a Hash from which you can get the wanted value.

$json_text = file('the_path_to_the_file.json') # see documentation
$data = parsejson($json_text)
$x = $data['data']  # get the value "foobar" in your example
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-11-28 12:21:55 -0600

Seen: 1,248 times

Last updated: Nov 29 '16