Jo – a shell command to create JSON (2016)
I remember that when I worked at Google about a decade ago, there was this common saying:<p>"If the first version of your shell script is more than five lines long, you should have written it in Python."<p>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 Javascript, it would have been far more obvious what the resulting output would have been, considering that those languages already use {} for objects and [] for lists.<p>For example, take this example:<p><pre><code>    jo -p name=JP object=$(jo fruit=Orange point=$(jo x=10 y=20) number=17) sunday=false
</code></pre>
In Python you would write it like this:<p><pre><code>    json.dumps({"name": "JP", "object": {"fruit": "Orange", "point": {"x": 10, "y": 20}, "number": 17}, "sunday": False})
</code></pre>
Only a bit more code, but at least it won't suffer from the Norway problem. Even though Python isn't the fastest language out there, it's likely still faster than the shell command above. There is no need to construct a fork bomb just to generate some JSON.