Answer the question
In order to leave comments, you need to log in
How can a nested hash be obtained from the value in that hash?
I want to get the entire hash only by value from a JSON file. Example:
{
"company": {
"employee": {
"first_employee": {
"id": 1,
"position": "farmer",
"age": 25,
"name": "Michael"
},
"second_employee": {
"id": 2,
"position": "builder",
"age": 29,
"name": "Steve"
}
}
}
}
require "json"
file = File.read("example.json")
data_hash = JSON.parse(file)
#Далее пример (Псевдокод):
p data_hash["position" = "farmer"]
#Должно выдать:
"first_employee": {
"id": 1,
"position": "farmer",
"age": 25,
"name": "Michael"
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question