I have an XML response from a URL that is being converted into an array of hashes which looks like:
{
"EmployeeList"=>{
"EmployeeProfile"=>{
"BuildLoc"=>{"$"=>"1 Happy Place"},
"Status"=>{"$"=>"A"},
"SecrTitle"=>[{}, {}],
"ID"=>{},
"bct"=>{},
"NUM"=>{"$"=>"1234567"},
"BuildCity"=>{"$"=>"Dayton"},
"BuildFloor"=>{"$"=>"6"},
"Expense"=>{"$"=>"1345"},
"LastName"=>{"$"=>"Smith"},
"Middle"=>{},
"SecrName"=>[{}, {}],
"InternalSMTPAddress"=>{"$"=>"Joe.Smith@happy.com"},
"IAddress"=>{"$"=>"Joe.Smith@happy.com"},
"PreferredLastName"=>{},
"DisplayName"=>{"$"=>"Joe Smith"},
"CellPhoneNo"=>{},
"Title"=>{"$"=>"Dr."},
"BuildStreetAddress"=>{"$"=>"123 Happy town"},
"BuildState"=>{"$"=>"IL"},
"FirstName"=>{"$"=>"Joe"},
"AltContactTitle1"=>{},
"Dept-CostCtrNo"=>{"$"=>"129923"},
"PreferredFirstName"=>{"$"=>"Joe"},
"AltContactName2"=>{},
"AltContactPhone2"=>{},
"GDP"=>{},
"BuildZip"=>{"$"=>"112345"},
"RegionID"=>{"$"=>"NAMR"},
"EmploymentType"=>{"$"=>"E"},
"TempPhone"=>{},
"BuildID"=>{"$"=>"01114"},
"CountryAbbr"=>{"$"=>"USA"},
"FaxDisp1"=>{},
"BuildCountry"=>{"$"=>"United States"}
}
},
nil=>nil
}
What’s the easiest way to extract the value of “DisplayName” and “InternalSMTPAddress“?
If you assign the returned hash to a variable named “
hash” you can access the two desired values for those keys like:and
If you want the actual data in them add a trailing
['$']: