Skip to main content
added 1730 characters in body
Source Link
Emjey
  • 2.1k
  • 3
  • 21
  • 36
    {
  "data": {
    "perksAndWellBeing": [
      {
        "title": "Physical Wellbeing",
        "perks": [
          {
            "id": "1234""a3N33000EAO",
            "logo": "https:"933000001P3v1AAC-1.png",
            "logoLarge": "https:"\33000001P3v6AAC-1.png",
            "title": "LiveHealth""LiveHealth Online",
            
          },
          {
            "id": "a3N3""a3N3300AO",
            "logo": "https:"\/\-attachments\/06933000001P3uwAAC-1.png",
            "logoLarge": "https:"/hments\/06933000001P3umAAC-1.png",
            "title": "One Medical",
            
          },
          {
            "id": "a3N3300EA4",
            "logo": "https:\/\/s33000001P3vQAAS-1.png",
            "logoLarge": "https:\/06933000001P3vVAAS-1.png",
            "title": "Access To Top Specialists",
            
          }
        ]
      },
      {
        "title": "Emotional Wellbeing",
        "perks": [
          {
            "id": null,
            "logo": "https:\"\/\/s00001P3vpAAC-1.png",
            "logoLarge": "https:\/"\/attachmeOAAS-1.png",
            "title": "Visit Guardian"Guardian EAP",
            
          }
        ]
      },
      {
        "title": "Financial Wellbeing",
        "perks": [
          {
            "id": "a3N3300HEA4",
            "logo": "https:\/\/sg",
            "logoLarge": "https:\/SAAS-1.png",
            "title": "Track your finances and get free access to financial advice",
            
          }]],
          {
            "id": "a3N33000EA4",
            "logo": "https:\/\/s",
            "logoLarge": "https:\/\/",
            "title": "Better student loan refinancing, mortgages, and personal loans",
          
          }
        ]
      },
      {
        "title": "Perks",
        "perks": [
          {
            "id": "a3N3300LxEAO",
            "logo": "https:\/\",
            "logoLarge": "https:\/,
            "title": "Anthem Programs",
            
          },
          {
            "id": "a3N3300000EA4",
            "logo": "https:\",
            "logoLarge": "https:\",
            "title": "Receive gym discounts, travel discounts, and more",
            
          }
        ]
      }
    ]
  }
}
{
  "data": {
    "perksAndWellBeing": [
      {
        "title": "Physical Wellbeing",
        "perks": [
          {
            "id": "1234",
            "logo": "https:",
            "logoLarge": "https:",
            "title": "LiveHealth",
            
          },
          {
            "id": "a3N3",
            "logo": "https:",
            "logoLarge": "https:",
            "title": "One Medical",
            {
        "title": "Emotional Wellbeing",
        "perks": [
          {
            "id": null,
            "logo": "https:\",
            "logoLarge": "https:\/",
            "title": "Visit Guardian",
            
          }
        ]
      },
          }]]}}}
    {
  "data": {
    "perksAndWellBeing": [
      {
        "title": "Physical Wellbeing",
        "perks": [
          {
            "id": "a3N33000EAO",
            "logo": "https:933000001P3v1AAC-1.png",
            "logoLarge": "https:\33000001P3v6AAC-1.png",
            "title": "LiveHealth Online",
            
          },
          {
            "id": "a3N3300AO",
            "logo": "https:\/\-attachments\/06933000001P3uwAAC-1.png",
            "logoLarge": "https:/hments\/06933000001P3umAAC-1.png",
            "title": "One Medical",
            
          },
          {
            "id": "a3N3300EA4",
            "logo": "https:\/\/s33000001P3vQAAS-1.png",
            "logoLarge": "https:\/06933000001P3vVAAS-1.png",
            "title": "Access To Top Specialists",
            
          }
        ]
      },
      {
        "title": "Emotional Wellbeing",
        "perks": [
          {
            "id": null,
            "logo": "https:\/\/s00001P3vpAAC-1.png",
            "logoLarge": "https:\/\/attachmeOAAS-1.png",
            "title": "Visit Guardian EAP",
            
          }
        ]
      },
      {
        "title": "Financial Wellbeing",
        "perks": [
          {
            "id": "a3N3300HEA4",
            "logo": "https:\/\/sg",
            "logoLarge": "https:\/SAAS-1.png",
            "title": "Track your finances and get free access to financial advice",
            
          },
          {
            "id": "a3N33000EA4",
            "logo": "https:\/\/s",
            "logoLarge": "https:\/\/",
            "title": "Better student loan refinancing, mortgages, and personal loans",
          
          }
        ]
      },
      {
        "title": "Perks",
        "perks": [
          {
            "id": "a3N3300LxEAO",
            "logo": "https:\/\",
            "logoLarge": "https:\/,
            "title": "Anthem Programs",
            
          },
          {
            "id": "a3N3300000EA4",
            "logo": "https:\",
            "logoLarge": "https:\",
            "title": "Receive gym discounts, travel discounts, and more",
            
          }
        ]
      }
    ]
  }
}
Source Link
Emjey
  • 2.1k
  • 3
  • 21
  • 36

Accessing json key associated value

This is my json file, and I would want to retrieve the value present in the key title that is under a list. i.e LiveHealth , OneMedical and visit guardian

{
  "data": {
    "perksAndWellBeing": [
      {
        "title": "Physical Wellbeing",
        "perks": [
          {
            "id": "1234",
            "logo": "https:",
            "logoLarge": "https:",
            "title": "LiveHealth",
            
          },
          {
            "id": "a3N3",
            "logo": "https:",
            "logoLarge": "https:",
            "title": "One Medical",
            {
        "title": "Emotional Wellbeing",
        "perks": [
          {
            "id": null,
            "logo": "https:\",
            "logoLarge": "https:\/",
            "title": "Visit Guardian",
            
          }
        ]
      },
          }]]}}}

Currently, I am able to retrieve the title's that has value as Physical wellbeing and Emotional wellbeing but I am not able to access the values in the list.

perkswellbeing = JSON.parse(perks)
  #puts perkswellbeing
  puts "*********************"
  g = JSON.parse(perks)
  result1 = g["data"]["perksAndWellBeing"].select {|g1| g1['title']}
  result1.each do |rest1|
    $perks = rest1['title']
    puts $perks

Not sure what Am I missing! Could anyone please help me out.