I have JSON data as follows-
var raw = {"raw":[{"W4Jlp9HKx_MVImNZuJwPqA!!:dgIN_ZskRAf5OtpgZ7tYLQ!!":{"name":"Name1","uniqID":"W4Jlp9HKx_MVImNZuJwPqA!!:dgIN_ZskRAf5OtpgZ7tYLQ!!"},"uFzQkOcsEwmRDGlob11Qiw!!:ArYiisKagqjnqMGfbKP7Yw!!":{"name":"Name2","uniqID":"uFzQkOcsEwmRDGlob11Qiw!!:ArYiisKagqjnqMGfbKP7Yw!!"},"fWcL6bvhCvp1wO95-7K3LA!!:XNYxDArq9E_6u2yaDbST0A!!":{"name":"Name3","uniqID":"fWcL6bvhCvp1wO95-7K3LA!!:XNYxDArq9E_6u2yaDbST0A!!"}}]}
The keys are dynamic, i.e., the first key "W4Jlp9HKx_MVImNZuJwPqA!!:dgIN_ZskRAf5OtpgZ7tYLQ!!" changes with every call we make to the JSON URL.
I want to parse the JSON data and store the data in Javascript variables.
I have tried to parse this with-
var arra = JSON.parse(raw);
And tried to get the value using
arra.raw[0].W4Jlp9HKx_MVImNZuJwPqA!!:dgIN_ZskRAf5OtpgZ7tYLQ!!.name
But this isn't helping, I do not get the values in this. I am not sure why this is happening as well. Is it because keys contain special characters?
It would be great if there is a way to list down the keys as well and fetch values with key index or something like that, i.e., something like
arra.raw[0].key(0).name
Wherein I don't have to give the key, as it changes with every call. Even if not a working solution using key name would suffice for now.
I'd prefer to achieve this in Javascript, if it isn't possible, please feel free to let me know in what language it can be achieved.
Thanks a bunch!
--- Edit ---
The answer to getting the value using key with special characters has been given in the comments, I had to use [] notation to fetch the result. Thanks a lot guys!! But the second question about fetching results using key position, than the key name remains open.