In my JS code, I need to convert the JSON response from server to a dictionary so that I can access them by key names. Here is the situation:
Say, this is the JSON response from my server:
{
'status': 'success',
'employees' : [
{ 'id': 12, 'name': 'Tom', 'department': 'finance' },
{ 'id': 34, 'name': 'Dick', 'department': 'admin' },
{ 'id': 56, 'name': 'Harry', 'department': 'marketing' }
]
}
Now what i need is to create a dictionary variable such that the key is the id and the value is the (say) name so that i can access them variable.id or variable[id_value] (from a loop).
How can this be achieved? Your help highly appreciated.
Thanks