Just a heads up to anyone using jq - I've previously spent a couple of hours debugging a problem because jq uses float64 to store integers (which might lead to rounding-errors/overflows). For example: echo 1152921504606846976 | jq 1152921504606847000
Not jq but JS itself. Here's the epic jwz rant on it: https://www.jwz.org/blog/2010/10/every-day-i-learn-something... with Brendan Eich chiming in: https://www.jwz.org/blog/2010/10/every-day-i-learn-something...
Faster and simpler with the command line: deep-comparing JSON files with jq
81–90 of 93 posts
Re: Faster and simpler with the command line: deep-comparing JSON files with jq
#82Earlier quoted context omitted.
awk, sed?
For extracting a value out of json where the keys can arbitrarily re-order and you have nested maps containing the same key names? No thanks.
Re: Faster and simpler with the command line: deep-comparing JSON files with jq
#83Re: Faster and simpler with the command line: deep-comparing JSON files with jq
#84It's worth mentioning that there are much faster JSON parsing libraries than the default in Ruby stdlib. I still don't think Ruby is the best choice for doing raw JSON parsing. Last time I had to care about JSON speed we were transforming billions of events and the Ruby JSON lib was becoming a bottleneck
> It's worth mentioning that there are much faster JSON parsing libraries than the default in Ruby stdlib. I am on the edge of my seat now. Would you mind listing which libraries are much (say, an order of magnitude) faster?
Re: Faster and simpler with the command line: deep-comparing JSON files with jq
#85Just a heads up to anyone using jq - I've previously spent a couple of hours debugging a problem because jq uses float64 to store integers (which might lead to rounding-errors/overflows). For example: echo 1152921504606846976 | jq 1152921504606847000
This is an artifact of JavaScript, which even as of ES6 uses IEEE 754 double-precision floats for all numeric values. jq likely uses the same implementation internally for compatibility reasons and to avoid surprises of a different kind. See https://www.ecma-international.org/ecma-262/6.0/#sec-ecmascr...
Re: Faster and simpler with the command line: deep-comparing JSON files with jq
#86Just a heads up to anyone using jq - I've previously spent a couple of hours debugging a problem because jq uses float64 to store integers (which might lead to rounding-errors/overflows). For example: echo 1152921504606846976 | jq 1152921504606847000
Not jq but JS itself. Here's the epic jwz rant on it: https://www.jwz.org/blog/2010/10/every-day-i-learn-something... with Brendan Eich chiming in: https://www.jwz.org/blog/2010/10/every-day-i-learn-something...
Re: Faster and simpler with the command line: deep-comparing JSON files with jq
#87Earlier quoted context omitted.
it's a bit weird, but it's perfect for writing quick shell one liners with once you get used to it. no regular scripting language can match it for that
awk, sed?
Re: Faster and simpler with the command line: deep-comparing JSON files with jq
#88Earlier quoted context omitted.
jq is a C program. In theory a truly specific program could work better. In practise, the broad scope of jq allows you to discover the operations you need and respond to changes in requirements without being locked into custom code, and any given programmer probably couldn't do the same job better.
jq is a C program, yes, but jq programs are interpreted. Because jq is a dynamically-typed language, it wouldn't be easy to compile it to object code that would run too much faster than the byte-interpreted version (though it would still run faster). As you say, jq's power is that it is an expressive language, and it's much much easier to write jq programs that work than it is to write C/C++ programs as needed that d…
Re: Faster and simpler with the command line: deep-comparing JSON files with jq
#89Earlier quoted context omitted.
(1) Try a language with fast allocations (C, C++, Rust, maybe Go or Java) -- anything except Python or Ruby or (2) Try using streaming API (I don't know Ruby, but quick google found https://github.com/dgraham/json-stream ). Note that this method will require you to massively restructure your program -- you want to avoid having all of the data in memory at once. The streaming API might work better with jq-based prepro…
Python is fast at parsing JSON, Go had hard time to match parsing speed of it. Additionally you have PyPy to help.
That's an important caveat. Python's C JSON parser library is super-fast, but if you want to use the data for anything but a simple equality check afterwards, it'll be slow as molasses.
Or you'll write a C extension for it...
Re: Faster and simpler with the command line: deep-comparing JSON files with jq
#90Earlier quoted context omitted.
Not jq but JS itself. Here's the epic jwz rant on it: https://www.jwz.org/blog/2010/10/every-day-i-learn-something... with Brendan Eich chiming in: https://www.jwz.org/blog/2010/10/every-day-i-learn-something...
Note: the links currently redirect to https://imgur.com/32R3qLv (image of a testicle and derogatory comment on HN)