Live data from Hacker News

A Faster Alternative to Jq

micahkepe.com

261–270 of 281 posts

Re: A Faster Alternative to Jq

#261
post #232
post #137

Jq's syntax is so arcane I can never remember it and always need to look up how to get a value from simple JSON.

Funny that everyone is linking the tools they wrote for themselves to deal with this problem. I am no exception. I wrote one that just lets you write JavaScript. Imagine my surprise that this extremely naive implementation was faster than jq, even on large files. $ cat package.json | dq 'Object.keys(data).slice(0, 5)' [ "name", "type", "version", "scripts", "dependencies" ] https://crespo.business/posts/dq-its-just-j…

Thanks. Can you say more about why TypeScript with Deno is your scripting language of choice?

Re: A Faster Alternative to Jq

#263
post #261
post #232

Earlier quoted context omitted.

Funny that everyone is linking the tools they wrote for themselves to deal with this problem. I am no exception. I wrote one that just lets you write JavaScript. Imagine my surprise that this extremely naive implementation was faster than jq, even on large files. $ cat package.json | dq 'Object.keys(data).slice(0, 5)' [ "name", "type", "version", "scripts", "dependencies" ] https://crespo.business/posts/dq-its-just-j…

Thanks. Can you say more about why TypeScript with Deno is your scripting language of choice?

I’ve always meant to write a post about this. Bun is pretty similar and has the `$` helper from dax built in. In the past I would have used Python for scripts that were too complicated for Bash. But the type system in Python is still not great. TypeScript’s is great: flexible, intuitive, powerful inference so you don’t have to do many annotations. And Deno with URL imports mean you can have a single-file script with external dependencies and it just works. (Python does this now too with inline dependencies and uv run.) Deno and Bun also come with decent APIs that are not quite a standard library but help a lot. Deno has a stdlib too.

https://docs.deno.com/runtime/reference/std/

You can see in my other scripts in my dotfiles that between dax for shelling out and cliffy or commander.js as a CLI builder, TS is a great language for building little CLIs.

https://github.com/david-crespo/dotfiles/tree/main/bin

Re: A Faster Alternative to Jq

#264

Earlier quoted context omitted.

I'm not GP, I use jq all the time, but I each time I use it I feel like I'm still a beginner because I don't get where I want to go on the first several attempts. Great tool, but IMO it is more intuitive to JSON people that want a CLI tool than CLI people that want a JSON tool. In other words, I have my own preconceptions about how piping should work on the whole thing, not iterating, and it always trips me up. Here'…

Trying to make a generic pipeline for json arrays because you don’t know the field names?

Why the f would they want to hardcode the field names?

Re: A Faster Alternative to Jq

#266

One problem I have not seen addressed by jq or alterataives, perhaps this one addresses it, is "JSON-like" data. That is, JSON that is not contained in a JSON file For example, web pages sometimes contain inline "JSON". But as this is not a proper JSON file, jq-style utilties cannot process it The solution I have used for years is a simple utility written in C using flex^1 (a "filter") that reformats "JSON" on stdin,…

*alternatives

Re: A Faster Alternative to Jq

#267

Earlier quoted context omitted.

Trying to make a generic pipeline for json arrays because you don’t know the field names?

Why the f would they want to hardcode the field names?

Because usually I am dealing with data I know not anonymous data

Re: A Faster Alternative to Jq

#269
post #232
post #137

Jq's syntax is so arcane I can never remember it and always need to look up how to get a value from simple JSON.

Funny that everyone is linking the tools they wrote for themselves to deal with this problem. I am no exception. I wrote one that just lets you write JavaScript. Imagine my surprise that this extremely naive implementation was faster than jq, even on large files. $ cat package.json | dq 'Object.keys(data).slice(0, 5)' [ "name", "type", "version", "scripts", "dependencies" ] https://crespo.business/posts/dq-its-just-j…

Love it. This is so clearly the way to solve the jq writeability problem. I’m going to replace jq with this immediately.
Post reply on HN