# Re: Loading a text of json file into a hash every run

**URL:** <https://discourse.chef.io/t/re-loading-a-text-of-json-file-into-a-hash-every-run/3591>\
**Category:** Chef Infra (archive)\
**Created:** [February 8, 2013, 6:44pm UTC](https://discourse.chef.io/t/re-loading-a-text-of-json-file-into-a-hash-every-run/3591 "2013-02-08T18:44:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Igor\_Serebryany](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/igor_serebryany/32/362_2.png) [@Igor\_Serebryany](https://discourse.chef.io/u/Igor_Serebryany)\
**Post date:** [February 8, 2013, 6:44pm UTC](https://discourse.chef.io/t/re-loading-a-text-of-json-file-into-a-hash-every-run/3591/1 "2013-02-08T18:44:16Z")

</div>

david,

you can do this with ruby pretty easily; looks like your file is json so  
just do this somewhere in your recipe:

contents = File.read(filename)  
hash = JSON.parse(contents)

however, you should probably be storing that data in chef attributes from  
the beginning. it's just as easy to edit those as it is to edit a file, and  
a lot more flexible.

--igor

On Fri, Feb 8, 2013 at 5:42 AM, David Montgomery  
[davidmontgomery@gmail.com](mailto:davidmontgomery@gmail.com)wrote:

> Hi,
> 
> I have a file that on every run needs to load a cookbook into a hash so I  
> can use in a subsequent template.
> 
> So, how do Load e.g.
> 
> {  
> "a": "b",  
> "c": "d"}
> 
> from a recipe into a hash from a text file? Ruby block? I perform python but what ever works.
> 
> Thanks
