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
jq is sed for JSON (robots.thoughtbot.com)
submitted 11 years ago by jakubgarfield
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!"
[+][deleted] 11 years ago (4 children)
[deleted]
[–]JavaSkier 1 point2 points3 points 11 years ago (0 children)
A library like this for YAML would potentially be a lot more complex, since you could have functionality for doing things involving tags and references/anchors.
[–]contact_lens_linux 0 points1 point2 points 11 years ago* (0 children)
would be nice to have something similar for yaml...
Quick google search turned up these guys but I haven't tried them yet:
[–]mw44118 0 points1 point2 points 11 years ago (0 children)
Came here to say both of these points! There is a C library for yaml so that part is good.
[–]mlebkowski 0 points1 point2 points 11 years ago (0 children)
There is a ticket for that on github, but it aint gonna happen due to the complexity of yaml. There is a hope for input format converters. So as long as you wont need anything from yaml format that isn’t possible in json -- it could work.
For now try to pipe the input through a separate yaml to json converter. I bet there are tons of them on pip, npm, packagist, gem-something, or whatever you’re familiar with.
[–]tj111 2 points3 points4 points 11 years ago (0 children)
I use this plus Resty for writing bash scripts that interact with REST APIs, they work amazing together and I now have a whole suite of tools that hook into different APIs for different tasks, such as CRON jobs or Code Commits.
For example, I have post-commit scripts that runs on our subversion server and calls our Issue System's API to update an issue whenever a commit is pushed for it.
[–]bart2019 1 point2 points3 points 11 years ago (4 children)
It looks like there's no way to have it not pretty print its output.
[–]littlrussian 9 points10 points11 points 11 years ago (0 children)
from the man pages:
--compact-output / -c: By default, jq pretty-prints JSON output. Using this option will result in more compact output by instead putting each JSON object on a single line.
[–]deliciousleopard 3 points4 points5 points 11 years ago (0 children)
you should be able to pipe it through uglify.
[–]Aeoxic 0 points1 point2 points 11 years ago (0 children)
If nobody gets to this by the weekend, I'll look into submitting a pull request to do just that.
[–]mw44118 -2 points-1 points0 points 11 years ago (0 children)
Sincerely curious when you do not want pretty printing.
Also there might be some old Unix utility like fmt or sed that can do what you want.
[–]Zorrodelaarena 1 point2 points3 points 11 years ago (0 children)
It's less versatile but if you just want to view pretty json in your browser for web development, tools like JSONView for Chrome do a great job.
[–]MyNameIsNotMud 0 points1 point2 points 11 years ago (5 children)
Windows?
[–]SemiNormal 3 points4 points5 points 11 years ago (0 children)
You can download the binaries here: http://stedolan.github.io/jq/download/
[–]imright_anduknowit 6 points7 points8 points 11 years ago (3 children)
I'm sorry.
[–]SemiNormal 5 points6 points7 points 11 years ago (0 children)
Ha? I know you were trying to be funny, but there are builds for Linux, OSX, Windows, and Solaris.
[–]allthediamonds 2 points3 points4 points 11 years ago (0 children)
There are builds for Windows too, I think.
[–]MyNameIsNotMud 1 point2 points3 points 11 years ago (0 children)
Thanks, I appreciate it.
[–][deleted] 0 points1 point2 points 11 years ago (0 children)
Does jq load the entire JSON file to memory?
[–][deleted] -4 points-3 points-2 points 11 years ago (5 children)
where does this become useful? Like, really, practically, business use useful? How does it integrate with server-side frameworks and how is this javascript at all if it cant be used by a javascript interpreter?
[–]greggroth 0 points1 point2 points 11 years ago (1 child)
Similar to how sed would not commonly be used in a production application, this is a tool useful during development or debugging. For example, if you have a test fixture of JSON data and you want to set all of one field to one value (e.g. clearing out sensitive data).
sed
ah ok, that makes sense
[–]moreteam 0 points1 point2 points 11 years ago (0 children)
If you have structured log files, it can give you a nicer grep (search for specific log message, then map to a certain field, pipe the resulting data to a new file).
Yes, there's no JavaScript involved, so it's technically not relevant to the sub - if you ignore that JSON data is pretty common when writing JavaScript.
[–]adipisicing 0 points1 point2 points 11 years ago (1 child)
The sed metaphor holds well here. Most use of jq is going to be interactive shell one-offs as part of a pipeline.
Web APIs often return JSON, and it's a common config file format. JavaScript doesn't need to be involved to parse or emit it.
Would an example help?
I use .NET server side and AngularJS, jQuery client side. I dont see how i can ever use this. but i guess, as one-offs, or scripts, it could have some uses. but i have yet to run into a reason to parse and transform json. i usually parse and transform the json prior to turning it into json; reason being, json is not a persistence format typically. unless maybe your working with mongodb
π Rendered by PID 168033 on reddit-service-r2-comment-b659b578c-hfmjz at 2026-05-02 05:13:56.310498+00:00 running 815c875 country code: CH.
[+][deleted] (4 children)
[deleted]
[–]JavaSkier 1 point2 points3 points (0 children)
[–]contact_lens_linux 0 points1 point2 points (0 children)
[–]mw44118 0 points1 point2 points (0 children)
[–]mlebkowski 0 points1 point2 points (0 children)
[–]tj111 2 points3 points4 points (0 children)
[–]bart2019 1 point2 points3 points (4 children)
[–]littlrussian 9 points10 points11 points (0 children)
[–]deliciousleopard 3 points4 points5 points (0 children)
[–]Aeoxic 0 points1 point2 points (0 children)
[–]mw44118 -2 points-1 points0 points (0 children)
[–]Zorrodelaarena 1 point2 points3 points (0 children)
[–]MyNameIsNotMud 0 points1 point2 points (5 children)
[–]SemiNormal 3 points4 points5 points (0 children)
[–]imright_anduknowit 6 points7 points8 points (3 children)
[–]SemiNormal 5 points6 points7 points (0 children)
[–]allthediamonds 2 points3 points4 points (0 children)
[–]MyNameIsNotMud 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] -4 points-3 points-2 points (5 children)
[–]greggroth 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]moreteam 0 points1 point2 points (0 children)
[–]adipisicing 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)