-2

I wrote a function to create geoJSON, and it spits out results such as the following:

{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"StreetAddress":"3112 Gaddis Road, Canton, Georgia 30115","Name":"Woodmont","Bedrooms":"6-Mar","Bathrooms":"5-Feb","Garage":"2","StartPrice":"Mid $300s","Soldout":"FALSE"},"geometry":{"coordinates":[-84.35505189999999,34.2319281],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"7040 Majors Road, Cumming, Georgia 30040","Name":"Ashford Manor Enclave","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"2","StartPrice":"$375,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.2036578,34.1641024],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"977 Woodbury Road, Canton, Georgia 30114","Name":"River Green","Bedrooms":"7-Mar","Bathrooms":"2.5-6","Garage":"2","StartPrice":"$245,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.524852,34.219029],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"3983 Paul Samuel Rd NW, Kennesaw, Georgia 30152","Name":"Summerhour","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"3","StartPrice":"$375,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.6657365,33.9875893],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4550 Hickory Road, Holly Springs, Georgia 30115","Name":"Oakhaven","Bedrooms":"6-Mar","Bathrooms":"2.5-5","Garage":"2","StartPrice":"$272,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.4282121,34.1675759],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"3210 Five Forks Trickum Rd, Lilburn, Georgia 30047","Name":"Brookstone Preserve","Bedrooms":"7-Apr","Bathrooms":"6-Feb","Garage":"2","StartPrice":"High $300s","Soldout":"FALSE"},"geometry":{"coordinates":[-84.06380329999999,33.8794093],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4950 Hickory Road, Woodstock, Georgia 30188","Name":"Woodhaven Court","Bedrooms":"4-Feb","Bathrooms":"3-Feb","Garage":"2","StartPrice":"$252,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.420323,34.16809],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"5615 Grand Reunion Drive, Hoschton, Georgia 30548","Name":"Reunion","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"2","StartPrice":"$274,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-83.863038,34.114602],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"922 Wooten Lake Road, Kennesaw, Georgia 30144","Name":"Falls Crest","Bedrooms":"4-Feb","Bathrooms":"3-Feb","Garage":"2","StartPrice":"$292,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.5774563,34.05599],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"105 Park Haven Lane, Tyrone, Georgia 30290","Name":"River Crest","Bedrooms":"7-Apr","Bathrooms":"2.5-6.5","Garage":"3-Feb","StartPrice":"$292,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.5801833,33.508861],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"413 Spring View Drive, Woodstock, Georgia 30188","Name":"Woodview Enclave","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"3-Feb","StartPrice":"$318,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.4685219,34.1075786],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"1340 Terrell Mill Road, Marietta, Georgia 30067","Name":"Ivy Crest","Bedrooms":"4-Mar","Bathrooms":"2.5-3.5","Garage":"2","StartPrice":"$341,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.46576999999999,33.9195719],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4604 Shiloh Road, Cumming, Georgia 30040","Name":"Shiloh Ridge","Bedrooms":"6-Apr","Bathrooms":"2.5-5.5","Garage":"2","StartPrice":"$357,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.2027887,34.1456647],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"2750 Kimball Bridge Road , Alpharetta, Georgia 30009","Name":"The Walk at Braeden","Bedrooms":"4-Feb","Bathrooms":"2-3.5","Garage":"2","StartPrice":"$378,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.2779815,34.0626187],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"1057 N Jamestown Road, Decatur, Georgia 30033","Name":"Parkside at Mason Mill - The Overlook","Bedrooms":"4-Mar","Bathrooms":"2-3.5","Garage":"2","StartPrice":"$420,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.3031443,33.8114372],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4400 West Atlanta Road SE, Smyrna, Georgia 30080","Name":"4400 West","Bedrooms":"4-Mar","Bathrooms":"2.5-3.5","Garage":"2","StartPrice":"$429,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.49285309999999,33.845839],"type":"Point"}}]}

For whatever reason, it refuses to work unless I go in and physically hit enter in my text editor to break up each line in the Features array. Strictly speaking I'm not sure why this works, or how I can change my function to write code that's copy-paste ready. Any ideas as to what is going wrong here?

edit: to be clear, I get an unidentified token error when I attempt to assign this to a variable, and my JavaScript breaks. I'm not sure why I'm getting downvoted for what is apparently a good question, since nobody has solved the issue yet.

Picture 1 of the json "breaking" invisibly: enter image description here

After enabling soft wrap and then hitting enter a couple of times in between each item of the feature array, you can see this about halfway to working:

enter image description here

In order for it to fully work, I would have to hit enter for every single item to break the lines. I hope my question is clear now.

edit 2 - Here's an issue I found related to a bug that causes the syntax highlighting to break: bug

Still, that shouldn't cause the JSON to otherwise be invalid.

Here's what it looks like after I've hit enter on everything:

working

To make matters even more odd, the geojson works fine as is if I enter it into codepen.

yoursweater
  • 1,883
  • 3
  • 19
  • 41
  • Are you asking about how to pretty print your JSON? If so this might help. https://stackoverflow.com/a/7220510/5086349 – Jason Allshorn Dec 21 '17 at 18:24
  • 4
    Can you further describe what you mean by "it refuses to work"? Your have valid JSON (tested with JSON.parse). – vox Dec 21 '17 at 18:27
  • Sure - in other words when I assign it to a variable and try to run it in JavaScript, I get an error. Specifically, unidentified token error. – yoursweater Dec 21 '17 at 18:36
  • 1
    I am unable to replicate this issue in any environment I have access to. Does JohnnyCoder's snippet execute for you? Can you please provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) that leads to the unidentified token error? – vox Dec 21 '17 at 18:47
  • No, JohnnyCoder's snippet has no effect. I'll try to cut this into an example. In the meanwhile, I just posted some picture so you can see more clearly what I'm talking about. – yoursweater Dec 21 '17 at 18:50
  • `"Bedrooms" : "7-Apr", "Bathrooms" : "6-Feb"` Huh? Sure all of your data really says what you think it says? Maybe something being parsed as a number that actually isn't? – mc01 Dec 21 '17 at 18:53
  • Those columns were off in their data, but it shouldn't affect what is technically valid JSON – yoursweater Dec 21 '17 at 18:55
  • Well, you say you get an "unidentified token" error in some function, not shown, which indicates a character it's not expecting when parsing something, which often indicates a typo - missed bracket, missing quotes, or e.g. letters when it's expecting numbers instead ... Based on your edits, now it's not clear if you're concerned about the syntax highlighting "breaking" or the error in your function. Which are you asking about? Editors can still be weird & it wouldn't affect the actual data - 2 separate things. Can you share the function & the actual error? – mc01 Dec 21 '17 at 19:01

1 Answers1

-1

const yourJSON = {"type":"FeatureCollection","features":[{"type":"Feature","properties":{"StreetAddress":"3112 Gaddis Road, Canton, Georgia 30115","Name":"Woodmont","Bedrooms":"6-Mar","Bathrooms":"5-Feb","Garage":"2","StartPrice":"Mid $300s","Soldout":"FALSE"},"geometry":{"coordinates":[-84.35505189999999,34.2319281],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"7040 Majors Road, Cumming, Georgia 30040","Name":"Ashford Manor Enclave","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"2","StartPrice":"$375,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.2036578,34.1641024],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"977 Woodbury Road, Canton, Georgia 30114","Name":"River Green","Bedrooms":"7-Mar","Bathrooms":"2.5-6","Garage":"2","StartPrice":"$245,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.524852,34.219029],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"3983 Paul Samuel Rd NW, Kennesaw, Georgia 30152","Name":"Summerhour","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"3","StartPrice":"$375,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.6657365,33.9875893],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4550 Hickory Road, Holly Springs, Georgia 30115","Name":"Oakhaven","Bedrooms":"6-Mar","Bathrooms":"2.5-5","Garage":"2","StartPrice":"$272,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.4282121,34.1675759],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"3210 Five Forks Trickum Rd, Lilburn, Georgia 30047","Name":"Brookstone Preserve","Bedrooms":"7-Apr","Bathrooms":"6-Feb","Garage":"2","StartPrice":"High $300s","Soldout":"FALSE"},"geometry":{"coordinates":[-84.06380329999999,33.8794093],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4950 Hickory Road, Woodstock, Georgia 30188","Name":"Woodhaven Court","Bedrooms":"4-Feb","Bathrooms":"3-Feb","Garage":"2","StartPrice":"$252,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.420323,34.16809],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"5615 Grand Reunion Drive, Hoschton, Georgia 30548","Name":"Reunion","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"2","StartPrice":"$274,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-83.863038,34.114602],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"922 Wooten Lake Road, Kennesaw, Georgia 30144","Name":"Falls Crest","Bedrooms":"4-Feb","Bathrooms":"3-Feb","Garage":"2","StartPrice":"$292,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.5774563,34.05599],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"105 Park Haven Lane, Tyrone, Georgia 30290","Name":"River Crest","Bedrooms":"7-Apr","Bathrooms":"2.5-6.5","Garage":"3-Feb","StartPrice":"$292,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.5801833,33.508861],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"413 Spring View Drive, Woodstock, Georgia 30188","Name":"Woodview Enclave","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"3-Feb","StartPrice":"$318,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.4685219,34.1075786],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"1340 Terrell Mill Road, Marietta, Georgia 30067","Name":"Ivy Crest","Bedrooms":"4-Mar","Bathrooms":"2.5-3.5","Garage":"2","StartPrice":"$341,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.46576999999999,33.9195719],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4604 Shiloh Road, Cumming, Georgia 30040","Name":"Shiloh Ridge","Bedrooms":"6-Apr","Bathrooms":"2.5-5.5","Garage":"2","StartPrice":"$357,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.2027887,34.1456647],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"2750 Kimball Bridge Road , Alpharetta, Georgia 30009","Name":"The Walk at Braeden","Bedrooms":"4-Feb","Bathrooms":"2-3.5","Garage":"2","StartPrice":"$378,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.2779815,34.0626187],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"1057 N Jamestown Road, Decatur, Georgia 30033","Name":"Parkside at Mason Mill - The Overlook","Bedrooms":"4-Mar","Bathrooms":"2-3.5","Garage":"2","StartPrice":"$420,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.3031443,33.8114372],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4400 West Atlanta Road SE, Smyrna, Georgia 30080","Name":"4400 West","Bedrooms":"4-Mar","Bathrooms":"2.5-3.5","Garage":"2","StartPrice":"$429,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.49285309999999,33.845839],"type":"Point"}}]};

const prettyFormat = JSON.stringify(yourJSON, null, 2);

document.querySelector('#inJSON')
    .innerText = JSON.stringify(yourJSON);
document.querySelector('#outJSON')
    .innerText = JSON.stringify(yourJSON, null, 2);
<h3>RAW:</h3>
<pre id="inJSON"></pre>

<h3>Formatted:</h3>
<pre id="outJSON"></pre>

How about using JSON.stringify?

const yourJSON = {"type":"FeatureCollection","features":[{"type":"Feature","properties":{"StreetAddress":"3112 Gaddis Road, Canton, Georgia 30115","Name":"Woodmont","Bedrooms":"6-Mar","Bathrooms":"5-Feb","Garage":"2","StartPrice":"Mid $300s","Soldout":"FALSE"},"geometry":{"coordinates":[-84.35505189999999,34.2319281],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"7040 Majors Road, Cumming, Georgia 30040","Name":"Ashford Manor Enclave","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"2","StartPrice":"$375,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.2036578,34.1641024],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"977 Woodbury Road, Canton, Georgia 30114","Name":"River Green","Bedrooms":"7-Mar","Bathrooms":"2.5-6","Garage":"2","StartPrice":"$245,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.524852,34.219029],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"3983 Paul Samuel Rd NW, Kennesaw, Georgia 30152","Name":"Summerhour","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"3","StartPrice":"$375,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.6657365,33.9875893],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4550 Hickory Road, Holly Springs, Georgia 30115","Name":"Oakhaven","Bedrooms":"6-Mar","Bathrooms":"2.5-5","Garage":"2","StartPrice":"$272,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.4282121,34.1675759],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"3210 Five Forks Trickum Rd, Lilburn, Georgia 30047","Name":"Brookstone Preserve","Bedrooms":"7-Apr","Bathrooms":"6-Feb","Garage":"2","StartPrice":"High $300s","Soldout":"FALSE"},"geometry":{"coordinates":[-84.06380329999999,33.8794093],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4950 Hickory Road, Woodstock, Georgia 30188","Name":"Woodhaven Court","Bedrooms":"4-Feb","Bathrooms":"3-Feb","Garage":"2","StartPrice":"$252,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.420323,34.16809],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"5615 Grand Reunion Drive, Hoschton, Georgia 30548","Name":"Reunion","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"2","StartPrice":"$274,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-83.863038,34.114602],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"922 Wooten Lake Road, Kennesaw, Georgia 30144","Name":"Falls Crest","Bedrooms":"4-Feb","Bathrooms":"3-Feb","Garage":"2","StartPrice":"$292,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.5774563,34.05599],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"105 Park Haven Lane, Tyrone, Georgia 30290","Name":"River Crest","Bedrooms":"7-Apr","Bathrooms":"2.5-6.5","Garage":"3-Feb","StartPrice":"$292,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.5801833,33.508861],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"413 Spring View Drive, Woodstock, Georgia 30188","Name":"Woodview Enclave","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"3-Feb","StartPrice":"$318,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.4685219,34.1075786],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"1340 Terrell Mill Road, Marietta, Georgia 30067","Name":"Ivy Crest","Bedrooms":"4-Mar","Bathrooms":"2.5-3.5","Garage":"2","StartPrice":"$341,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.46576999999999,33.9195719],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4604 Shiloh Road, Cumming, Georgia 30040","Name":"Shiloh Ridge","Bedrooms":"6-Apr","Bathrooms":"2.5-5.5","Garage":"2","StartPrice":"$357,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.2027887,34.1456647],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"2750 Kimball Bridge Road , Alpharetta, Georgia 30009","Name":"The Walk at Braeden","Bedrooms":"4-Feb","Bathrooms":"2-3.5","Garage":"2","StartPrice":"$378,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.2779815,34.0626187],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"1057 N Jamestown Road, Decatur, Georgia 30033","Name":"Parkside at Mason Mill - The Overlook","Bedrooms":"4-Mar","Bathrooms":"2-3.5","Garage":"2","StartPrice":"$420,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.3031443,33.8114372],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4400 West Atlanta Road SE, Smyrna, Georgia 30080","Name":"4400 West","Bedrooms":"4-Mar","Bathrooms":"2.5-3.5","Garage":"2","StartPrice":"$429,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.49285309999999,33.845839],"type":"Point"}}]};

const prettyFormat = JSON.stringify(yourJSON, null, 2);
User 1058612
  • 3,739
  • 1
  • 27
  • 33