I'm working with Google's civic info API and I'm trying to figure out how to convert a JSON repsonse into a variable javascript object (we'll call that object civicInfoObject). Then I want to display to contents of that object onto the page with HTML. I'm new to javascript and haven't been able to successfully come up with a solution or find an answer.
It's a relative big project for me so I am working in bite-size pieces. I copied and pasted the JSON response to my query and created a new HTML document with it. So basically my goal right now is to store this static JSON string in a variable (civicInfoResponse), convert it into an object and store that in a variable (civicInfoObject), and then display the contents of that object onto a page with HTML.
Here is my strategy thus far:
var civicInfoResponse = "copy-and-pasted string
that spans
multiple lines"
var civicInfoObject = JSON.parse(civicInfoResponse);
document.getElementById("Info").innerHTML = civicInfoObject;
Here is the fiddle I created so you can see the JSON response in its entirety: https://jsfiddle.net/km38o815/2/
The code I wrote might be completely wrong, I'm not sure. I'm having a hard time with my limited knowledge about javascript. Can anyone help me out or at least point me in the right direction? It would be very much appreciated. Thanks!