Hash Arrays

Monday, Apr 6, 2020 | 1 minute read | Updated at Monday, Apr 6, 2020

@
Hash Arrays

Man got stuck working with Google matric Api to determine distance, duration of travel etc from two points on the map.

values the api spat out was a jumble of hash values that took me a while to understand how to traverse it.


matrix = 
{
  "destination_addresses":["Egypt Rd, Accra, Ghana"],
  "origin_addresses":["8 Third Dade Walk, Accra, Ghana"],
  "rows":
  [
    {"elements":
      [
        {
          "distance":
          {
            "text":"5.0 km",
            "value":5047
            },
          "duration":
          {
            "text":"12 mins",
            "value":734
            },
            "status": "OK"
            }
              ]
               }
              ],
              "status":"OK"
              }

Ever wondered how to traverse an array/hash like this? code snippet below will output : "5.0km"

matrix[:rows][0][:elements][0][:distance][:text]

Think on it !!

© 2025 Reveries

🌱 Powered by Hugo with theme Dream.

Me

Self Introduction

Passionate about people & technology. With a plethora of experience managing both people and technology. I am currently a Technical Officer with the Communications Division of CSIR - Institute for Scientific and Technological Information. Here, I am responsible for transforming research outputs into software, tools, equipments and communication systems as tools for national development.

I am BIG about community and have spent the better part of the last decade; growing and managing various tech communities in Ghana. Most recent being the Google Developer Group (GDG). I ASPIRE to INSPIRE.

I like to dabble in a lot of technology related things; from code to Rpi’s.