5 ms·
> contains the locations of the chain’s hotels in JSON. Using a regular expression, I converted the hotel data into CSV. wat.
by daurnimator 12y ago
> contains the locations of the chain’s hotels in JSON. Using a regular expression, I converted the hotel data into CSV.
wat.
- arnarbi 12y agoI agree with others that it doesn't matter in this case. The author used a tool he knows to perform a simple job. At the risk of providing something useful to the discussion though, I'd like to point out the excellent tool jq: http://stedolan.github.io/jq/ http://stedolan.github.io/jq/ Here's how to use it for the conversion in the article: jq '.places[] | [.n,.i,.p[0],.p[1],.s] | map(tostring) | join(",")' hotelMarkers.js (after editing hotelMarkers.js into a proper json file)
- DirtyAndy 12y agoI would assume because PostgreSQL (the DB he is using) doesn't support importing from JSON?
- wtetzner 12y agoBut why not use a JSON parser?
- idlewords 12y agoThe dude had a whimsical idea, tried it out, and wrote it up for our enjoyment. Let it go. Maybe he will parse the JSON next time.
- deleted 12y ago[deleted]
- aaronbrethorst 12y agoNext you're going to say you didn't build Pinboard with Angular, or something crazy like that.
- knodi123 12y agoif you're driving a nail into soft wood, you could use a hammer... Or you could just use a rock, or another piece of wood, or.... Using the wrong tool for a really easy job can sometimes be faster than the minimal effort of getting the right tool ready.
- wtetzner 12y agoI guess, but honestly using a JSON parser sounds like less work. I mean, using regexes for this quick job is fine, it just sounded weird.
- jlarocco 12y agoOn the one hand I agree with the "It doesn't matter here" crowd, but on the other hand, Python (only language mentioned in the article) has a json library in the stdlib, and it's certainly easier than doing it with regexes. So, it doesn't matter much, but it was an odd choice.
- recursive 12y agoEven if it's in the standard library, it still might be more work to find where it is in the standard library than just do it the way you already know how.
- weaksauce 12y agoAgreed... It's a devil you know vs. the "oh I'll just use this other library to do $simple_thing, how hard can it really be?" Hours later you realize that you didn't think it completely through and it's a bit tougher than you thought.
- aestra 12y ago>it's certainly easier than doing it with regexes. ... for you.
- coolj 12y agoThe regexp must have taken some time to write and debug: s/^."n":"(.+)","i":"(.+)","p":\[([\d\.\-]+),([\d\.\-]+)],"s":"(\w+)","c":"(.+)".$/\1,\2,\3,\4,\5/;
- rosser 12y agoIt depends on the version. More recent releases (that is, >= 9.2) do have native JSON support, but it's still young — though steadily improving.
- sk5t 12y agoYup, I've done a bit with 9.2, and it accepts JSON just fine (although not with automatic string conversion) but it's a short road to wishing the data were in standard tables and columns.
- dizzystar 12y agoUse dollar-quoting for automatic string conversion: insert into my_table values ($$ json_goes_here $$); Works for all stringy things.
- sk5t 12y agoCool, thanks. Last time around I used a pg-driver-specific datatype to hold the parameter on its way through sql2o, and felt rather guilty about doing so.
- zackbloom 12y agoIt was a bit odd to me, but I was willing to accept that it might be faster than figuring out the API for spitting out csv, but when he did exactly that for the XML extraction...
- w-ll 12y agoComma separated values (or CSV) [1] format is dead simple; more simple than JSON, you just need a print function. 1. http://en.wikipedia.org/wiki/Comma-separated_values#Basic_rules_and_examples http://en.wikipedia.org/wiki/Comma-separated_values#Basic_ru...
- fnordfnordfnord 12y agoYou kids and your fancy API's. I remember back in the day when we had to... something something regexes.
- deleted 12y ago[deleted]
- staunch 12y agoDoesn't everybody? http://www.perlmonks.org/?node_id=995856 http://www.perlmonks.org/?node_id=995856
- psykovsky 12y agoAnd here is the reason I will never post code I write.
- dopamean 12y agoI feel the same way. Heaven forbid that I do something that I know how to do that gets the job done and it's not the perfect way or is even, perhaps, completely silly. Let's focus on that thing and not the overall project.
- driverdan 12y agoWhy? If other people do something differently it's a great way to learn something new. Don't take it personally.
- stusmall 12y agoI think its more that the "wat." comment wasn't a chance to learn anything new. It was just snark.
- nobleach 12y agoIn the closed source GIS world JSON hasn't exactly taken the world by storm. In open source (and I'm assuming the author is pretty familiar, seeing as he's using Postgres) GeoJSON is the format of choice. Wrangling that data INTO GeoJSON would net little advantage all for the purpose of importing it into Postgres. For displaying the results in a wonderful tool like QGIS, I could see going the extra mile.
- untog 12y agoWho cares? It worked, didn't it? Maybe he knows regexes better than JSON parsers.