Mike Cuddy Mike Cuddy - 1 year ago 101
Javascript Question

JSON parsing and stringify

I am currently working on a Javascript project where I have to parse tons of data. The project requires that I parse some JSON data and bring specific data into another array. Right now, I am using the JSON.stringify method and I can console.log all of the data that I need. The data looks something like this:

"type": "FeatureCollection",
"features": [
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [

yes, this is not all that data-it is about 1200 pages long! I only pasted in the top segment of it. All I really need is how to get to the coordinates aspect of it and into an array. So what I am currently doing is this:

var work = JSON.stringify(response, null, 4)

Which gives me the above response. However, I am not that familiar with JSON.stringify so if I do:


Attempting to see what the value is for type, I get a response of undefined. Now if I try doing this:

var work = JSON.parse(response)

I get a response of: VM296:1 Uncaught SyntaxError: Unexpected token o in JSON at position 1

Thus, I cannot get the data parsed which I want to get to which will be the coordinates data. Any help with using stringify would great help me. I have read a lot about how it turns the data into a string but have not really seen a lot about how to parse it. Do I have to use parse? Thank you for your help!

Answer Source

You dont' have to use stringify or parse for this. The response object you are receiving is already a javascript object so you can reference its properties normally

response.type; // => "FeatureCollection"

If you try and stringify the response it will lose its type property, for instance:

typeof "some string".someProperty; // => undefined

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download