Ask Your Question
0

how to handle json data in puppet

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

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

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:

 {"request_id":"e2d2d0df-d797-6dca-fcbd-f046ba6eaabf","lease_id":"","renewable":false,"lease_duration":2764800,"data":{"value":"foobar"},"wrap_info":null,"warnings":null,"auth":null}

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
1

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

Henrik Lindberg gravatar image

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

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

Stats

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

Seen: 62 times

Last updated: Nov 29 '16