Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
kbrazil
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
8 ms
·
31.
▲
by
kbrazil
5y ago
I hadn’t seen this before - thanks for sharing!
32.
▲
by
kbrazil
5y ago
I typically run the command output through `cat` to see if it does different things when outputting to the terminal vs piping. The biggest changes are typically ANSI color codes and column length. Some programs do strange things, like chang
33.
▲
by
kbrazil
5y ago
I can’t think of one off the top of my head, so maybe I’m misremembering why I originally decided I preferred flatter structures. It’s possible it was due to some limitation on my part as I was first learning to work with JSON. Looking back
34.
▲
by
kbrazil
5y ago
The article is not advocating flattening willy nilly. The point is to have bias for flatter structures to make it easier for the user, but of course not all structures can or should be flat. On the other hand, don’t over-engineer your data
35.
▲
by
kbrazil
5y ago
In actuality most CLI output is quite small and can easily be represented as a single JSON document. There are a few commands that can produce huge amounts of output and those are good candidates for using JSON Lines as noted in the article
36.
▲
by
kbrazil
5y ago
You can also convert dig output to JSON with jc. (I’m the author) $ jc dig example.com | jq -r '.[].answer[].data' 93.184.216.34 https://github.com/kellyjonbrazil/jc
37.
▲
Tips on adding JSON output to your CLI app
(blog.kellybrazil.com)
183 points
by
kbrazil
5y ago
|
110 comments
38.
▲
by
kbrazil
5y ago
It's probably not the most correct, but it is a very common practice[0]. [0] https://stackoverflow.com/questions/23934425/parse-ifconfig-...
39.
▲
by
kbrazil
5y ago
Absolutely! I didn't write JC to be the be-all end-all. I wrote it because I believe using structured text between processes is usually better than plain text and this tool allows people to try it out and see for themselves. The goal i
40.
▲
by
kbrazil
5y ago
Ah, yes - that locale is not supported. From the Caveats section: For best results set the LANG locale environment variable to `C` or `en_US.UTF-8`. For example, either by setting directly on the command-line: $ LANG=C date | jc --date
41.
▲
by
kbrazil
5y ago
I wrote something similar to this to query JSON and JSON lines with python instead of awk for text. It’s called Jellex (Jello Explorer) which is a TUI front-end to Jello. Jello is a python analog to JQ. https://github.com/ke
42.
▲
by
kbrazil
5y ago
I feel like if that were true then you’d have the majority of REST APIs delivering unstructured output instead of structured JSON, XML, CSV, etc. The market has spoken - there is true utility in structured text output.
43.
▲
by
kbrazil
5y ago
JSON Lines is often used for this type of thing. https://jsonlines.org/
44.
▲
by
kbrazil
5y ago
I don’t follow. Your examples are of data formats standardized in the 80’s while Unix was developed in the 60’s and 70’s. JSON even existed before 2013, but the fact that it became a standard in addition to being popular is the point I was
45.
▲
by
kbrazil
5y ago
Sure thing! https://github.com/kellyjonbrazil/jello Other languages are superior in their handling of maps/arrays, but Python is just so damned popular now I thought it was a good choice to democratize JSON handli
46.
▲
by
kbrazil
5y ago
Odd. What locale are you using? Should work fine with C or en_UTF8, per the readme.
47.
▲
by
kbrazil
5y ago
I agree JSON is probably not right for every type of program output, but the age of web APIs has shown us that is probably great or adequate 90% of the time. If something is spewing out long lines of data I think JSON Lines would be a good
48.
▲
by
kbrazil
5y ago
Yes, I have seen those too! That’s why I also wrote Jello, which is like jq but uses pure python without the boilerplate. Python is nearly universal now and typically easy to read, though more verbose. Jq is just as much a write-once tool a
49.
▲
by
kbrazil
5y ago
That’s a good debate to have. I settled on JSON due to its readability and ubiquity in web APIs. It’s something people all the way down and up the stack are very familiar with these days.
50.
▲
by
kbrazil
5y ago
If the ifconfig output changes slightly, then it will probably break the thousands of ad-hoc parser implementations buried in scripts worldwide. With this approach, only a central parser library (open source) needs to be maintained so it ca
51.
▲
by
kbrazil
5y ago
I don’t think the issue is that it’s hard to manually parse. The problem is that it’s hard for someone else to read your ad-hoc parser years later and reason about what you did if they need to modify it. Disclaimer: I am the author of the a
52.
▲
by
kbrazil
6y ago
I have created JSON schemas for the output of dozens of commands and file-types with my jc[0] project. I tried to keep them as flat as possible, but there are many other ways it could have been done. Creating the schema many times requires
53.
▲
by
kbrazil
6y ago
Shameless plug - I created a cli tool called jtbl[0] that converts json output to tables in the terminal. [0] https://github.com/kellyjonbrazil/jtbl
54.
▲
by
kbrazil
6y ago
Shameless plug, but I created jello[0] to give you the ease of parsing json in bash, but using python syntax[1] [0] https://github.com/kellyjonbrazil/jello [1] https://blog.kellybrazil.com/2020/03&#x
55.
▲
by
kbrazil
6y ago
Shameless plug, but that was one of the reasons I created jello[0], which allows you to use pure python list/dict/comprehension, etc. syntax. Also, here is a blog post[1] explaining in more detail. [0] https://github.com
56.
▲
by
kbrazil
6y ago
There are other tools like jq that instead use more common syntax. For example, jello[0] is just like jq except it uses python list and dictionary syntax. (disclaimer: I am the author) [0] https://github.com/kellyjonbrazil&#
57.
▲
by
kbrazil
6y ago
jc[0] does this for many commands and file-types, including .ini and key/value pair files with various delimiters and comment identifiers. [0] https://github.com/kellyjonbrazil/jc (disclaimer: I am the author)
58.
▲
by
kbrazil
6y ago
This is what jc[0] does. [0] https://github.com/kellyjonbrazil/jc (disclaimer: I am the author)
59.
▲
by
kbrazil
6y ago
can you do that with netstat? :) (ls was one of the more simple parsers to write, aside from some corner cases)
60.
▲
by
kbrazil
6y ago
One use case that has come up is to parse the output of commands your run on remote hosts that may not even have python installed. I have a PR into Ansible community.general plugins to add this functionality and it works pretty sweet. There
More ›