In my JS code, I need to convert the JSON response from the server to a dictionary so that I can access them by keywords. Here is the situation:
Let's say this is a 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 I need to create a dictionary variable so that the key is id and the value is the name (say), so that I can access them variable.id or variable [id_value] (from the loop).
How can this be achieved? Your help is much appreciated.
Thanks Vivek Ragunathan
source share