[SOLVED] Query JSON Using a variable?

Hi i have a bunch of JSON data for mattresses. I can access my JSON easily using something like:

this.appManagerScript.mattressData.brands.products.Purple_Original.info_text[0])

…but how do I go about accessing the same data for for this using a variable for the name of the mattress.(instead of having to write it explicitly eg ‘Purple_Original’) Eg…

this.appManagerScript.mattressData.brands.products.(THIS IS MY VARIABLE).info_text[0])

My variable is modified depending on user input.

There must be a way of inserting variables into JSON search queries no?

Hi @Grimmy,

That’s a valid question, you can do so using the following statement:

this.appManagerScript.mattressData.brands.products['THIS IS MY VARIABLE'].info_text[0])
1 Like

Perfect. Thank You. I was pretty close with my guess :slight_smile:

1 Like

Yeah! Dynamic property names are a powerful JS feature.

1 Like