Neat. An ad hoc alternative to this if you have Python 2.7 handy and can't or don't want to compile C code could be something like<p><pre><code> $ python -c 'import json, sys;\
kv = sys.argv[1::];\
v = [int(x) if x.isdigit() else eval(x.title()) if x in ["false", "true"]\
else x for x in kv[1::2]];\
print json.dumps(dict(zip(kv[::2], v)), ensure_ascii=False, indent=2)
' key1 value1 key2 'string value 2' number 5589 boolean1 true boolean2 false
</code></pre>
which produces the output<p><pre><code> {
"key2": "string value 2",
"key1": "value1",
"number": 5589,
"boolean2": false,
"boolean1": true
}
</code></pre>
I, for one, am excited to hear that native JSON (and XML, and HTML) output is coming to FreeBSD's userland courtesy of libxo (see <a href="https://wiki.freebsd.org/LibXo" rel="nofollow">https://wiki.freebsd.org/LibXo</a>). I hope GNU Core Utilities eventually go the same way or a full-featured alternative appears for Linux that does.