Having a JSON object labeled test
with values like this: {"items":[{"name":"test"}]}
, I need a way to apply the string items[0].name
to it in order to search for a specific value (test.items[0].name
). Currently, my only idea is to create a function that parses square brackets and dots. Is there an alternative method, possibly involving eval (though I prefer to avoid it)?
To clarify, I have a JSON object where the details are not important. What matters is being able to query the object using a string, such as theobject.items[0]
. The challenge lies in the fact that the query string (e.g., items[0]
) is unknown - consider it user input stored as a string (var thisIsAString = "items[0]"
). So, I require a way to append this query string to theobject
in order to retrieve the value at theobject.items[0]
.