1

I need to remove the attribute nested1 that is inside the attr7_nested in a massive way, I don't need to persist this data in the bank, just store it in a variable to send to a log file.

example file follows:

[{
  "attr1": 120,
  "attr2": 24,
  "attr3": 11400,
  "attr4": "Caixa",
  "attr5": 2000000,
  "attr6": 1744000,
  "attr7_nested": {
    "nested1": 1,
    "nested2": "Essential",
    "nested3": "med",
    "nested4": "Med"
  }
},
{
  "attr1": 120,
  "attr2": 24,
  "attr3": 11400,
  "attr4": "Caixa",
  "attr5": 2000000,
  "attr6": 1744000,
  "attr7_nested": {
    "nested1": 1,
    "nested2": "Ess",
    "nested3": "med",
    "nested4": "Med"
  }
}]

1 Answer 1

1

When array is the array containing the nested hashes from your question than the following would remove the nested1 keys from all nested attr7_nested hashes:

array.each { |hash| hash[:attr7_nested].delete(:nested1) }
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much friend for your help, I'm a beginner in ruby, very good

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.