Live data from Hacker News

Jo – a shell command to create JSON (2016)

jpmens.net

61–70 of 100 posts

Re: Jo – a shell command to create JSON (2016)

#61

I remember that when I worked at Google about a decade ago, there was this common saying: "If the first version of your shell script is more than five lines long, you should have written it in Python." I think there's a lot of truth in that. None of the examples presented in the article look better than had they been written in some existing scripting/programming language. In fact, had they been written in Python or…

The longest shell script I ever wrote was at Google, because at the time, my co-worker and I didn't know anyone with Python readability.

Re: Jo – a shell command to create JSON (2016)

#62

I remember that when I worked at Google about a decade ago, there was this common saying: "If the first version of your shell script is more than five lines long, you should have written it in Python." I think there's a lot of truth in that. None of the examples presented in the article look better than had they been written in some existing scripting/programming language. In fact, had they been written in Python or…

> there was this common saying:

> "If the first version of your shell script is more than five lines long, you should have written it in Python."

Seriously, these kind of "common knowledge", "universal truth in a sentence" sayings are often the mark of wannabe guru mid career engineers that have no clue what they are talking about.

Re: Jo – a shell command to create JSON (2016)

#63
post #47

Earlier quoted context omitted.

If you're going to use string literal, then echo '{"name": "JP", "object": {"fruit": "Orange", "point": {"x": 10, "y": 20}, "number": 17}, "sunday": false}' is fine as a script

All fun and games until you need quoting. Quoting in shell scripts is already hellish enough, but layering JSON quoting on top of that is a road to madness.

Combining here-string with `jq` (if you need variables), is plenty good enough. You'd need a single jq invocation.

Re: Jo – a shell command to create JSON (2016)

#64
post #62

I remember that when I worked at Google about a decade ago, there was this common saying: "If the first version of your shell script is more than five lines long, you should have written it in Python." I think there's a lot of truth in that. None of the examples presented in the article look better than had they been written in some existing scripting/programming language. In fact, had they been written in Python or…

> there was this common saying: > "If the first version of your shell script is more than five lines long, you should have written it in Python." Seriously, these kind of "common knowledge", "universal truth in a sentence" sayings are often the mark of wannabe guru mid career engineers that have no clue what they are talking about.

This is a toxic comment that adds nothing to the conversation.

Re: Jo – a shell command to create JSON (2016)

#65
post #63

Earlier quoted context omitted.

All fun and games until you need quoting. Quoting in shell scripts is already hellish enough, but layering JSON quoting on top of that is a road to madness.

Combining here-string with `jq` (if you need variables), is plenty good enough. You'd need a single jq invocation.

Yes, `jq` would work fine, but so would `jo`. The point is, if there is anything more than the simplest dynamic values, constructing valid JSON just with POSIX shell is a huge pain.

Re: Jo – a shell command to create JSON (2016)

#66
post #62

Earlier quoted context omitted.

> there was this common saying: > "If the first version of your shell script is more than five lines long, you should have written it in Python." Seriously, these kind of "common knowledge", "universal truth in a sentence" sayings are often the mark of wannabe guru mid career engineers that have no clue what they are talking about.

This is a toxic comment that adds nothing to the conversation.

I don't know, the jo command seems a lot more readable to me than compressing json to a one line string. How is it toxic to call out a silly truthism?

Re: Jo – a shell command to create JSON (2016)

#67

I remember that when I worked at Google about a decade ago, there was this common saying: "If the first version of your shell script is more than five lines long, you should have written it in Python." I think there's a lot of truth in that. None of the examples presented in the article look better than had they been written in some existing scripting/programming language. In fact, had they been written in Python or…

I just assume at this point that a new python script from a coworker won’t run without an hour of tinkering and yelling obscenities at my screen. Or resorting to running in docker, which seems asinine. Python’s everywhere and does everything though, so I don’t have a good alternative. Shell scripts definitely aren’t it, but they generally hold up better when sharing in my experience.

Re: Jo – a shell command to create JSON (2016)

#68
This looks like an informally specified shell-friendly alternative json syntax.

I wonder if a formal syntax would help? Perhaps including relevant shell syntax (interpolation, subshell). It could clarify issues, and this different perspective might suggest improvements or different approaches.

Re: Jo – a shell command to create JSON (2016)

#69
post #47

Earlier quoted context omitted.

If you're going to use string literal, then echo '{"name": "JP", "object": {"fruit": "Orange", "point": {"x": 10, "y": 20}, "number": 17}, "sunday": false}' is fine as a script

All fun and games until you need quoting. Quoting in shell scripts is already hellish enough, but layering JSON quoting on top of that is a road to madness.

[deleted]

Re: Jo – a shell command to create JSON (2016)

#70

I remember that when I worked at Google about a decade ago, there was this common saying: "If the first version of your shell script is more than five lines long, you should have written it in Python." I think there's a lot of truth in that. None of the examples presented in the article look better than had they been written in some existing scripting/programming language. In fact, had they been written in Python or…

> it's likely still faster than the shell command above.

That's not a shell command any more than running "python" is. `jo` is its own executable.

And doing the sub-commands are not necessary; `jo` supports nested data natively.

Post reply on HN