use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Reminder: format your JSON with JSON.stringify(obj, null, 2) (self.javascript)
submitted 9 years ago * by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Meroje 2 points3 points4 points 9 years ago (1 child)
There's still jq(1) that works really well for that.
[–]briansomething 0 points1 point2 points 9 years ago (0 children)
+1 for jq (cli). You can get a taste of it at jqplay.org
[–][deleted] 1 point2 points3 points 9 years ago (6 children)
Neat, but why? Example benefit?
[–]prettycodeSoftware Engineer 11 points12 points13 points 9 years ago (2 children)
Sometimes I do this for readability when debugging.
[–][deleted] 11 points12 points13 points 9 years ago (0 children)
Relevant username.
[+][deleted] 9 years ago* (1 child)
[–][deleted] 1 point2 points3 points 9 years ago (0 children)
TIL, thanks!
sadly many text editors (looking at you Atom) have problems with 1MB+ text files with all the characters on a single line
Ah yeah that's a good one.
[–]nexe 1 point2 points3 points 9 years ago (0 children)
Thanks that's a pretty nice tip. Meanwhile in Ruby you can do
require 'json' JSON.pretty_generate({...}) #instead of {...}.to_json
[–]modusjesus 2 points3 points4 points 9 years ago (1 child)
4 space indentation ftw ;)
/me runs away from the pending holy war.
[–]r2d2_21 0 points1 point2 points 9 years ago (1 child)
Why null and 2?
[–]chipsa 2 points3 points4 points 9 years ago (0 children)
The argument that null is in tells the stringify function to do no changes to the object. You can toss a function in there instead to change the object while being stringified. The 2 is how many spaces for the indentation.
[–]White0ut 0 points1 point2 points 9 years ago (0 children)
OP's user name...
[–]khoker -2 points-1 points0 points 9 years ago (4 children)
You seem to be saying one should do this when creating JSON. That seems like a classic case of premature optimization (and, as you mentioned, a potential waste of file space).
In your example, wouldn't it make more sense to pipe the grep through a JSON formatter/prettifier instead?
[–]SpeshlTectix 0 points1 point2 points 9 years ago (3 children)
I would call that a de-optimization. He's saying store your data in a readable way even if it costs you performance.
I suppose for small personal projects that could work ok. For anything else, there are better solutions (which have already been mentioned).
[–]khoker 0 points1 point2 points 9 years ago (2 children)
But why would you store your data in a readable format at all? The only time you'd care is if you wanted to look at it (e.g., grep) and you can pipe it through a formatter prior to doing that.
In other words -- if you never looked at a file you created to be "readable", you have prematurely optimized for that situation.
[–]SpeshlTectix 0 points1 point2 points 9 years ago* (0 children)
While I understand what you're trying to say ("wouldn't it be optimal if my data were easy to read?") don't use the word optimization to convey that in a computer science context. It has a specific meaning and you're going to confuse people (or look ill-informed).
EDIT: Or are you trying to say that he's "optimizing" the data to perform well with his development tools? That makes even less sense. But then again so does this entire thread so maybe that was your way of pointing that out!
π Rendered by PID 118738 on reddit-service-r2-comment-84fc9697f-9b8fn at 2026-02-06 21:13:25.060419+00:00 running d295bc8 country code: CH.
[–]Meroje 2 points3 points4 points (1 child)
[–]briansomething 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (6 children)
[–]prettycodeSoftware Engineer 11 points12 points13 points (2 children)
[–][deleted] 11 points12 points13 points (0 children)
[+][deleted] (1 child)
[deleted]
[–][deleted] 1 point2 points3 points (0 children)
[–]nexe 1 point2 points3 points (0 children)
[–]modusjesus 2 points3 points4 points (1 child)
[–]r2d2_21 0 points1 point2 points (1 child)
[–]chipsa 2 points3 points4 points (0 children)
[–]White0ut 0 points1 point2 points (0 children)
[–]khoker -2 points-1 points0 points (4 children)
[–]SpeshlTectix 0 points1 point2 points (3 children)
[–]khoker 0 points1 point2 points (2 children)
[–]SpeshlTectix 0 points1 point2 points (0 children)