I have an array that store some data like this and this is the exact input I'm using
{
"accepted" => {
"number_of_order" => {
"condition" => "between_number", "value" => "0&5"
}
}, "removed" => {
}
}
Now I'm trying to convert this array into ruby hash access like this and this is my expected output it's not what I'm getting now
--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
accepted: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
number_of_order: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
condition: between_number
value: 0&5
removed: !ruby/hash:ActiveSupport::HashWithIndifferentAccess {}
But I'm unable to convert the array in ruby hash access. I also try YAML dump Yaml::dump($array); to convert into YAML then ruby hash access but nothing works.
Basically, I'm trying to do reverse of this question
How to get data from ruby hash access to laravel 8?
You can refer above link I convert this ruby hash into a laravel array but now I also wanted to convert this array into ruby hash.
My current code for converting an array to a ruby hash
$jsonEncoded = '{"accepted":{"number_of_order":{"consition":"between_number","value":"0&5"}}}';
$array = json_decode($jsonEncoded, true);
dump(Yaml::dump($array));
My current code for converting ruby hash to array
$filter_data = str_replace("!ruby/hash:ActiveSupport::HashWithIndifferentAccess", "", $filter_data);
$yamlContents = Yaml::parse($filter_data);