'nested JSON ruby extract values

I want to extract the individual values by key out of this JSON.

json = JSON.parse({ "streams": [ { "index": 0, "codec_name": "mpeg2video"} ] })

Using json['streams'].each do |codec_name| returns the whole first array back. I also tried identifying specific array number by json['streams'][0].each do |codec_name| and that errors.

The output expected should be "mpeg2video"



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source