I need to parse data from one JSON file in order to validate arrays, keys, and values in a second JSON file. For example, I have a JSON file filled with data in this format:
{ "someData":["array", "key", "value"] }
I have a second JSON file with data like this:
{ "fruit": [ {"type":"apple"},
{"type":"cherry"},
{"type":"pear"} ] }
What I need to do is take the data from the first JSON file and use it to validate data in the second JSON file. Say my “someData” JSON looks like this:
{ "someData":["fruit", "type", "pear"] }
How can I create a straight javascript function to determine if the “fruit” array exists in the second JSON dictionary, with a key named “type”, and a value named “pear”? I guess what I’m really asking is how do I use a string from the first JSON dictionary in order to access data from the second JSON dictionary?
You can acces a property of an object either directly or if dynamically via dictionary notation (if you have its name as string):