Live data from Hacker News

Faster and simpler with the command line: deep-comparing JSON files with jq

genius.engineering

51–60 of 93 posts

Re: Faster and simpler with the command line: deep-comparing JSON files with jq

#51

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

Yikes, that's nasty.

It is. But it's a problem of JSON itself, not just jq.

Re: Faster and simpler with the command line: deep-comparing JSON files with jq

#52

> My first thought was to write a ruby script to parse and compare the two exports, but after spending a little time coding something up I had a program that was starting to get fairly complicated, didn't work correctly, and was too slow—my first cut took well over an hour. Then I thought: is this one of those situations where a simple series of shell commands can replace a complex purpose-built script? Key takeaway:…

[deleted]

Re: Faster and simpler with the command line: deep-comparing JSON files with jq

#53
post #51

Earlier quoted context omitted.

Yikes, that's nasty.

It is. But it's a problem of JSON itself, not just jq.

JSON != JavaScript

> echo 1152921504606846976 | python -c 'import sys, json; print(json.load(sys.stdin))'

1152921504606846976

Re: Faster and simpler with the command line: deep-comparing JSON files with jq

#54
post #20

That's cool, you made a thing that verifies the two export jobs you wrote have the same data even though they have different output. I can't help wondering, if you control the code that generates the JSON, why not output in a conservative, consistent format? I'm sure there are pros/cons, but this work would allow something like `diff` to work, and then you don't have to maintain a separate utility.

good question! the analysis that I was doing was really a one-off for switching between these processes. We have unit tests and sanity checks to ensure consistency going forward, but as a final check before flipping the switch we wanted to be as confident as possible that we hadn't introduced any regressions across the full data-set. The new export process is much more reliable and a _lot_ faster, but as a side effec…

I'm surprised the layout of the JSON doesn't arrange music by artist, any reasoning why that wasn't done?

Re: Faster and simpler with the command line: deep-comparing JSON files with jq

#55
I really enjoyed this article, and I think it shows how successfully jq fits into the Unix culture of sed/awk/grep/etc. It seems so rare to find new CLUI tools that feel as "classical" as jq. It has helped me do one-off tasks like this several times, but I've really only scratched the surface. Often with newer tools I'm reluctant to invest in going deeper into really learning the features, but with jq I have a lot of confidence that it would pay off for years to come. I don't see any books yet, but this is about the phase where I'd normally buy an O'Reilly volume (hint hint).

Btw I'm surprised you needed -M, since I thought jq would suppress colors if it saw it wasn't writing to a tty.

Re: Faster and simpler with the command line: deep-comparing JSON files with jq

#56
post #53
post #51

Earlier quoted context omitted.

It is. But it's a problem of JSON itself, not just jq.

JSON != JavaScript > echo 1152921504606846976 | python -c 'import sys, json; print(json.load(sys.stdin))' 1152921504606846976

Just because python has bigints and its stdlib json module supports bigints in json doesn't mean that is an interoperable thing to do.

Re: Faster and simpler with the command line: deep-comparing JSON files with jq

#58
post #53
post #51

Earlier quoted context omitted.

It is. But it's a problem of JSON itself, not just jq.

JSON != JavaScript > echo 1152921504606846976 | python -c 'import sys, json; print(json.load(sys.stdin))' 1152921504606846976

Python's json package != JSON

JSON: https://tools.ietf.org/html/rfc8259#page-8

Re: Faster and simpler with the command line: deep-comparing JSON files with jq

#60
post #53
post #51

Earlier quoted context omitted.

It is. But it's a problem of JSON itself, not just jq.

JSON != JavaScript > echo 1152921504606846976 | python -c 'import sys, json; print(json.load(sys.stdin))' 1152921504606846976

That's Python not adhering to the JSON standard as defined in the RFC.
Post reply on HN