JSON serialization for array of hashes not working properly anymore


#1

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…

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

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

#2

Try dropping back a version, 13.7.16 has a mean little regression: Regression in Chef Client 13.7.16


#3

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