I'm looking for a method that will flatten a "json" hash into a flattened hash but keep the path information in the flattened keys. For example:
h = {"a" => "foo", "b" => [{"c" => "bar", "d" => ["baz"]}]}
flatten(h) should return:
{"a" => "foo", "b_0_c" => "bar", "b_0_d_0" => "baz"}
I'm having a similar question and raised it here Best way to produce a flattened JSON (denormalize) out of hierarchical JSON in Ruby with a possible solution
Is my solution an optimal one or is there any better way?
This should solve your problem: