# JSON serialization for array of hashes not working properly anymore

**URL:** <https://discourse.chef.io/t/json-serialization-for-array-of-hashes-not-working-properly-anymore/12618>\
**Category:** Chef Infra (archive)\
**Created:** [February 21, 2018, 6:11pm UTC](https://discourse.chef.io/t/json-serialization-for-array-of-hashes-not-working-properly-anymore/12618 "2018-02-21T18:11:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gdurand](https://avatars.discourse-cdn.com/v4/letter/g/c2a13f/32.png) [@gdurand](https://discourse.chef.io/u/gdurand)\
**Post date:** [February 21, 2018, 6:11pm UTC](https://discourse.chef.io/t/json-serialization-for-array-of-hashes-not-working-properly-anymore/12618/1 "2018-02-21T18:11:45Z")

</div>

Hello,  
I store an array of hashes in an attribute and want to serialize this array to json:  
`default['services'] = [{ sri: 'org.apache.felix.deployment.rp.autoconf', version: '0.1.8', register: true }, { sri: 'sirlan-javolution', version: '5.2.6', register: true }]`

With the previous version of Chef, I used `node['services'].to_json` and the result was a complete json array as expected.  
But now this returns an empty array “[]”, although `node['services'][0].to_json` returns the first hash.  
If I use `Chef::JSONCompat.to_json(node['services'])`, I also get an empty array but if I use `Chef::JSONCompat.to_json(node['services'][0])` I get an empty object “{}”, though if I use `Chef::JSONCompat.to_json(node['services'][0]['sri'])` I get the sri string.  
If I replace the hashes with strings, then both `to_json` and `JSONCompat` produce an empty array.  
Any hint on how to solve this problem?

And the strangest thing is that a bit further in the recipe I build a hash that serializes fine…

```auto
version = {
    services: node['services'].map { |s| { sri: s['sri'], version: s['version'] } },
    configurations: distribution.configurations,
}

```

Chef client 13.7.16 on ubuntu server 16.04

```auto
$ ruby --version
ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]

```

---

<div class="post-metadata">

**Author:** ![cheeseplus](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/cheeseplus/32/960_2.png) [@cheeseplus](https://discourse.chef.io/u/cheeseplus)\
**Post date:** [February 21, 2018, 6:52pm UTC](https://discourse.chef.io/t/json-serialization-for-array-of-hashes-not-working-properly-anymore/12618/2 "2018-02-21T18:52:26Z")

</div>

Try dropping back a version, 13.7.16 has a mean little regression: [Regression in Chef Client 13.7.16](https://discourse.chef.io/t/regression-in-chef-client-13-7-16/12518)

---

<div class="post-metadata">

**Author:** ![gdurand](https://avatars.discourse-cdn.com/v4/letter/g/c2a13f/32.png) [@gdurand](https://discourse.chef.io/u/gdurand)\
**Post date:** [February 22, 2018, 8:20am UTC](https://discourse.chef.io/t/json-serialization-for-array-of-hashes-not-working-properly-anymore/12618/3 "2018-02-22T08:20:59Z")

</div>

OK, good to know.  
I ended up recreating the hash from the node and serialize this.
