Trying to access data from two dictionaries using JavaScript and having some trouble.
The JSON output received from the server is as follows:
{"meta":{},"linked":{"custom_fields":[{"id":"4","name":"Department"}],"custom_field_values":[{"id":"0001","value":"Marketing","links":{"custom_field":{"id":"4","type":"custom_fields"}}}]}
My goal is to display "Marketing" as the department, but I'm struggling to access the "links" property in order to retrieve the id.
When I create
var linked = linked.custom_field_values;
, I get a response that looks like this:
{"id":"0001","value":"Marketing","links":{"custom_field":{"id":"4","type":"custom_fields"}}}
However, when I attempt
var cfl = linked.links.custom_field.id
, it gives an error saying that "links" is not defined. It seems like there may be an issue with how I'm defining my variables?
The "links" property contains a dictionary with "Custom_field" nested underneath, which is where the necessary values are located.
If everything works correctly, shouldn't this code snippet print out the department accurately?
if(cfl.id == 4){
console.log('Department is ' + linked.value);
}