Newbie question working with JSON responses and arrays

Summing a set of values from an API response but getting confused
flipping between hashes and arrays. This feels like it should be really

All code provided below

sum = request[“orders”].reduce(0) do |sum,item|
sum + item[“total_price”].to_r
puts sum
puts sum.to_f

I converted the strings representing the prices to Rationals to avoid
rounding errors.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs