Currently my app is parsing JSON in following way:
OpenStruct.new(JSON.parse(json_string))
but there are problems with this approach:
- JSON allows root-level arrays like
[{id: 1, name: "first"}, {id: 2, name: "second"}]
and OpenStruct can't handle them throwing an exception. - OpenStruct does not handle nested elements.
I found some solutions like RecursiveOpenStruct and others.
- They handle nested hashes, but still can't handle top-level arrays
- Hashes nested into array remain hashes:
{data: [{id: 1, name: "first"}, {id: 2, name: "second"}]}
here each.data[i]
is a Hash.