122 points · by vyuh · 7y ago · 40 comments
Citation needed. The `jq` vs `jtc` section is interesting, but author seems a little full of himself with some of the explanations.
> jq is written in C, which drags all intrinsic problems the language has dated its creation
And then to follow on the C++ claims:
> Main JSON engine/library does not have a single new operator, nor it has a single naked pointer acting as a resource holder/owner, thus jtc is guaranteed to be free of memory leaks (at least one class of the problems is off the table) - STL guaranty.
That's a lot more faith than I would be willing to put into C++ or C. Sure, that claim might be correct, but there's enough edge cases and undefined behavior in the language that I take it as a fairly bold claim unless it's also been thoroughly reviewed for any places some undefined behavior may be induced.
I mean, it's probably fine, but just the willingness to make such a bold claim in that way communicates the opposite of what the author likely intended for me.
I can't even parse this sentence. What does it mean?
FWIW jq was originally written in Haskell, then ported to C. The C source for the core parts is strikingly clean. I think, it's partly from this Haskell heritage that jq gets its nice composability.
However, TBF, I do find I must refresh jq syntax whenever I use it (pr only bc I don't process json often). It will be interesting to see what jtc does - though this foreshadowing does not bode well...
Yeah, you don't know what you're talking about.
"Undefined behavior" simply means "stuff not covered by the ISO standard".
So Python and Rust are 100% UB, and people don't really care.
Perhaps the features used in this project protect against that, but my point is that undefined behavior and the way compilers deal with it is variable and problematic.
For those, I mostly use "jq ." to get all leaves on a single line and then feed the output to standard unix tools like grep cut awk and friends.
And for more complex tasks, python, perl, even C++ if speed is needed.
There's a tool called `gron` designed for workflows like this, I've found it incredibly useful.
https://news.ycombinator.com/item?id=16727665 https://github.com/tomnomnom/gron/
There's no reason why you would need to learn the whole DSL for simple tasks. Just learn what you need. For simple stuff, the DSL is also simple.
jtc also seems to have its own DSL by the way, and it doesn't really seem more intuitive than jq's:
jtc -x'[0][:][name]<person>v [-1][children]<kids:false>f[0]<kids:true>v' -T'{"{person} has children":{kids}}' -r
That's apparently the equivalent of: jq '.Directory | map({"\(.name) has children": (.children | length == 0)}) | .[]'
There are some things that seem simpler on jtc, though, like searches of string values without regard to the json structure.IMO the ideal solution is something using pure JavaScript syntax, possibly with a library resembling jQuery for tree traversal.
jq '.Directory | map({"\(.name) has children": (.children | length != 0)}) | .[]'HTML -> XML (via hxnormalize) -> JSON (via jtm) -> process using jtc (or even jq)
This is basically impossible to do in a way that is compatible with other tools. Things like duplicate attributes of an object can exist in XML, but not in JSON. You can still work-around these limitations if you just have a pipeline using the same toolset, but part of the point of these tools is to then convert them back to a format that some other tool can use, which is where this pattern breaks down.
Here's a list of pitfalls: https://stackoverflow.com/questions/33072812/potential-probl...
I'm not convinced that I would call this "simpler" than jq.
By contrast, this seems like one of the least intentionally designed pieces of CLI software I've seen.
$ wc -l conn.log
8505 conn.log
$ cat conn.log |time ~/src/jtc-standard.json/jtc -a -w '<uid>l' -qq |shasum
0.44 real 0.43 user 0.00 sys
167f6d638a4ccf9e0be1ff4ed74caa01a461bd9a -
$ cat conn.log | time jq -r .uid|shasum
0.10 real 0.10 user 0.00 sys
167f6d638a4ccf9e0be1ff4ed74caa01a461bd9a -
$ cat conn.log | time json-cut uid |shasum
0.04 real 0.01 user 0.01 sys
167f6d638a4ccf9e0be1ff4ed74caa01a461bd9a -
json-cut is a crappy tool I wrote that use github.com/buger/jsonparserPostgreSQL also calls the SQL/JSON path language “JSON Path”, and the data type is called `JSONPATH`.
Unfortunately, ".." just doesn't fit nicely with the "." operator of C-style languages.
I'm almost inclined to go full-XPath, and use "/", so I can use "..".
If I really wanted CLI, I would use one of those languages to write a program that reads arguments while making use of one of those JSON libraries.
It's time to stop admitting that (if the name is so terrible) and re-brand or, more likely, come up with a better backronym meaning for your name.