Get data from dynamic key value in json

The requirement is as follows:
I have to get the location field from the page.

var input= global.input = document.getElementById("Location"); 

Get neighborhood neighborhood from json file based on input and show on page.

I have a json object and have to filter data from a json object based on key value (location)

 var inputLocation=input.value; 

In my javascript, I get an error if I use a dynamic key.

I can get a json array if I do it data.Aspen , but I need to get the data from the text field, and it may be different, so if I call data.inputLocation ... its coming undefined

when i use data.(inputLocation.value) , getting the following error:

An XML filter is applied to a non-XML value ({Aspen: [{ID:

 { "Aspen":[ { "ID":"Bellaire", "Name":"Bellaire" }, { "ID":"Champions Forest", "Name":"Champions Forest" }, { "ID":"Highland Village", "Name":"Highland Village" }, { "ID":"Museum District", "Name":"Museum District" } ] } 
+6
json javascript key-value
source share
1 answer

You can access a property using a syntax like:

 data[inputLocation] 

If inputLocation set to "Aspen" , this is the same as these two lines:

 data["Aspen"] data.Aspen 
+34
source share

All Articles