HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
h4l
json.bash
Shell2024–2024
h4l / json.bash

json.bash

Command-line tool and bash library that creates JSON

2Distinct people
4Mentions
0Explicit recommenders
460GitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

Command-line tool and bash library that creates JSON

GitHub

Where it is used

No documented product use has been verified yet.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

No other repository is repeatedly linked in the same discussions.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 12:54:37 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by hour4 dated mentions

Observed mentions: 2024-07-03 10:18:00 UTC to 2024-07-03 17:39:25 UTC.

012024-07-03 10:00:00 UTC to 2024-07-03 11:00:00 UTC (exclusive): 1 mentions; 1 submissions, 0 commentsJul 3, 10:002024-07-03 11:00:00 UTC to 2024-07-03 12:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-07-03 12:00:00 UTC to 2024-07-03 13:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-07-03 13:00:00 UTC to 2024-07-03 14:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 commentsJul 3, 13:002024-07-03 14:00:00 UTC to 2024-07-03 15:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2024-07-03 15:00:00 UTC to 2024-07-03 16:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-07-03 16:00:00 UTC to 2024-07-03 17:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2024-07-03 17:00:00 UTC to 2024-07-03 18:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 commentsJul 3, 17:00

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
Jul 3, 10:002024-07-03 10:00:00 UTC2024-07-03 11:00:00 UTC110
Jul 3, 11:002024-07-03 11:00:00 UTC2024-07-03 12:00:00 UTC000
Jul 3, 12:002024-07-03 12:00:00 UTC2024-07-03 13:00:00 UTC000
Jul 3, 13:002024-07-03 13:00:00 UTC2024-07-03 14:00:00 UTC000
Jul 3, 14:002024-07-03 14:00:00 UTC2024-07-03 15:00:00 UTC101
Jul 3, 15:002024-07-03 15:00:00 UTC2024-07-03 16:00:00 UTC000
Jul 3, 16:002024-07-03 16:00:00 UTC2024-07-03 17:00:00 UTC101
Jul 3, 17:002024-07-03 17:00:00 UTC2024-07-03 18:00:00 UTC101

What Hacker News says

4 sources
This is incredibly high-quality BASH programming, as a fellow bash freak I am studying this code, and even I am learning some new techniques. https://github.com/h4l/json.bash/blob/main/json.bash You've boiled it down to a set of very elegant constructs. Respect. Thank you @h4l, this is badass. I hope you follow up with a golang or rust implementation, that would really be something else. p.s. I noticed the following odd behaviors with escaping delimiters (e.g. "="), is there a way to get an un-escaped equal sign as the trailing part of a key or leading part of a value? $ docker container run --rm ghcr.io/h4l/json.bash/jb msg=Hi {"msg":"Hi"} $ docker container run --rm ghcr.io/h4l/json.bash/jb msg=\=Hi {"msg=Hi":"msg=Hi"} $ docker container run --rm ghcr.io/h4l/json.bash/jb "msg=\=Hi" {"msg":"\\=Hi"} $ docker container run
Read the rest
--rm ghcr.io/h4l/json.bash/jb "msg\==\=Hi" {"msg\\=\\":"Hi"} $ docker container run --rm ghcr.io/h4l/json.bash/jb "msg\\==\=Hi" {"msg\\=\\":"Hi"} $ docker container run --rm ghcr.io/h4l/json.bash/jb "msg\\===Hi" {"msg\\=":"Hi"}
In Show HN: Jb / json.bash – Command-line tool (and bash library) that creates JSON
If it helps, there's a little example of using the bash API with bash variables/arrays, should give you an idea of how it could be to use: https://github.com/h4l/json.bash/blob/main/examples/notify.s... This example uses the pattern of setting an out=varname when calling a json function, the encoded JSON goes into $varname variable. This pattern avoids the overhead of forking processes (e.g. subshells) when generating JSON. Otherwise you can use the more normal approach of jb writing to stdout, and capturing the output stream.
In Show HN: Jb / json.bash – Command-line tool (and bash library) that creates JSON
As well as anyone's general thoughts/experiences, I'd appreciate opinions on the error handling mechanism jb uses to detect errors in upstream jb processes that jb is reading from. Normally, detecting errors on the other end of a pipe requires care in a shell environment (e.g. retrospectively checking PIPESTATUS). I used an approach I've called Stream Poisoning. It takes advantage of the fact that control characters are never present in valid JSON. When jb fails to encode JSON, it emits a Cancel control character[1] on stdout. When jb encounters such a character in an input, it can tell the input it's reading from is truncated/erroneous. This avoids the typical problem of a pipe silently being read as an empty file. I've got a page explaining this with some examples here: https://github.com/h4l/json.bash/blob/main/docs/stream-poiso... I c
Read the rest
an imagine using control characters in a text stream being rather controversial, but I feel it works quite well in practice. [1]: https://en.wikipedia.org/wiki/Cancel_character
In Show HN: Jb / json.bash – Command-line tool (and bash library) that creates JSON
h4l·Jul 3, 2024Submission

Show HN: Jb / json.bash – Command-line tool (and bash library) that creates JSON

jb is a UNIX tool that creates JSON, for shell scripts or interactive use. Its "one thing" is to get shell-native data (environment variables, files, program output) to somewhere else, using JSON encapsulate it robustly. I wrote this because I wanted a robust and ergonomic way to create ad-hoc JSON data from the command line and scripts. I wanted errors to not pass silently, not coerce data types, not put secrets into argv. I wanted to leverage shell features/patterns like process substitution, environment variables, reading/streaming from files and null-terminated data. If you know of the jo program, jb is similar, but type-safe by default and more flexible. jo coerces types, using flags like -n to coerce to a specific type (number for -n), without failing if the input is invalid. jb encodes values as strings by default, requiring type a
Read the rest
nnotations to parse & encode values as a specific type (failing if the value is invalid). If you know jq, jb is complementary in that jq is great at transforming data already in JSON format, but it's fiddly to get non-JSON data into jq. In contrast, jb is good at getting unstructured data from arguments, environment variables and files into JSON (so that jq could use it), but jb cannot do any transformation of data, only parsing & encoding into JSON types. I feel rather guilty about having written this in bash. It's something of a boiled frog story. I started out just wanting to encode JSON strings from a shell script, without dependencies, with the intention of piping them into jq. After a few trials I was able to encode JSON strings in bash with surprising performance, using array operations to encode multiple strings at once. It grew from there into a complete tool. I'd certainly not choose bash if I was starting from scratch now...
183 points · Open discussion

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.