JO(1)
π JO(1) β JSON output from a shell, bestie edition π
okay so like, jo is literally the main character of turning shell words into JSON, and I'm obsessed. It's giving "I make your shell scripts slay" energy. Periodt.
β¨ NAME β¨
jo β JSON output from a shell, no cap π«Ά
π¦ SYNOPSIS π¦
jo [-p] [-a] [-B] [-D] [-e] [-n] [-v] [-V] [-d keydelim] [-f file] [β] [
[-s|-n|-b] word ...]
πΈ DESCRIPTION πΈ
jo creates a JSON string on stdout from words you give it as arguments or read from stdin. iconic behavior tbh. If -f is specified, jo first loads the contents of file as a JSON object or array, then modifies it with subsequent words before printing the final JSON string to stdout. file may be specified as - to read from jo's standard input β this takes precedence over reading words from stdin, so like, watch out for that bestie.
Without option -a it generates an object whereby each word is a key=value (or key@value) pair with key being the JSON object element and value its value. jo attempts to guess the type of value in order to create number (using strtod(3)), string, or null values in JSON. it's literally doing the most to figure out what you meant π
A missing or empty value normally results in an element whose value is null. If -n is specified, this element is not created. so like, no value? no entry. simple as that.
jo normally treats key as a literal string value. If the -d option is specified, key will be interpreted as an object path, whose individual components are separated by the first character of keydelim. it's giving file system vibes but for JSON, iykyk.
jo normally treats value as a literal string value, unless it begins with one of the following characters:
@fileβ substitute the contents of file as-is π%fileβ substitute the contents of file in base64-encoded form π:fileβ interpret the contents of file as JSON, and substitute the result β¨
Escape the special character with a backslash to prevent this interpretation. protect the vibe, bestie π‘οΈ
jo treats key@value specifically as boolean JSON elements: if the value begins with T, t, or the numeric value is greater than zero, the result is true, else false. it's giving yes/no energy fr fr.
jo creates an array instead of an object when -a is specified. switch up the whole flow, love that for us.
When the := operator is used in a word, the name to the right of := is a file containing JSON which is parsed and assigned to the key left of the operator. The file may be specified as - to read from jo's standard input. it's like a little JSON delivery service π
π TYPE COERCION π
jo's type guesses can be overridden on a per-word basis by prefixing word with -s for string, -n for number, or -b for boolean. The list of words must be prefixed with --, to indicate to jo that there are no more global options. okay so like, boundaries, bestie.
Type coercion works as follows:
a=β-s:"a":""|-n:"a":0|-b:"a":false| default:"a":nulla=stringβ-s:"a":"string"|-n:"a":6|-b:"a":true| default:"a":"string"a="quoted"β-s:"a":""quoted""|-n:"a":8|-b:"a":true| default:"a":""quoted""a=12345β-s:"a":"12345"|-n:"a":12345|-b:"a":true| default:"a":12345a=trueβ-s:"a":"true"|-n:"a":1|-b:"a":true| default:"a":truea=falseβ-s:"a":"false"|-n:"a":0|-b:"a":false| default:"a":falsea=nullβ-s:"a":""|-n:"a":0|-b:"a":false| default:"a":null
Coercing a non-number string to number outputs the length of the string. so like, "This is a test" becomes 14 because that's how many characters, and honestly? that's iconic.
Coercing a non-boolean string to boolean outputs false if the string is empty, true otherwise. respect the truthiness, bestie.
Type coercion only applies to key=value words, and individual words in a -a array. Coercing other words has no effect. it's a vibe check and some words just don't pass, and that's fine π
π EXAMPLES π
Create an object. Note how the incorrectly-formatted float value becomes a string:
$ jo tst=1457081292 lat=12.3456 cc=FR badfloat=3.14159.26 name="JP Mens" nada= coffee@T
{"tst":1457081292,"lat":12.3456,"cc":"FR","badfloat":"3.14159.26","name":"JP Mens","nada":null,"coffee":true}
Pretty-print an array with a list of files in the current directory:
$ jo -p -a *
[
"Makefile",
"README.md",
"jo.1",
"jo.c",
"jo.pandoc",
"json.c",
"json.h"
]
Create objects within objects; this works because if the first character of value is an open brace or a bracket we attempt to decode the remainder as JSON. Beware spaces in strings ...
$ jo -p name=JP object=$(jo fruit=Orange hungry@0 point=$(jo x=10 y=20 list=$(jo -a 1 2 3 4 5)) number=17) sunday@0
{
"name": "JP",
"object": {
"fruit": "Orange",
"hungry": false,
"point": {
"x": 10,
"y": 20,
"list": [
1,
2,
3,
4,
5
]
},
"number": 17
},
"sunday": false
}
Booleans as strings or as boolean (pay particular attention to switch; the -B option disables the default detection of the "true", "false", and "null" strings):
$ jo switch=true morning@0
{"switch":true,"morning":false}
$ jo -B switch=true morning@0
{"switch":"true","morning":false}
Elements (objects and arrays) can be nested. The following example nests an array called point and an object named geo:
$ jo -p name=Jane point[]=1 point[]=2 geo[lat]=10 geo[lon]=20
{
"name": "Jane",
"point": [
1,
2
],
"geo": {
"lat": 10,
"lon": 20
}
}
The same example, using object paths:
$ jo -p -d. name=Jane point[]=1 point[]=2 geo.lat=10 geo.lon=20
{
"name": "Jane",
"point": [
1,
2
],
"geo": {
"lat": 10,
"lon": 20
}
}
Without -d, a different object is generated:
$ jo -p name=Jane point[]=1 point[]=2 geo.lat=10 geo.lon=20
{
"name": "Jane",
"point": [
1,
2
],
"geo.lat": 10,
"geo.lon": 20
}
Create empty objects or arrays, intentionally or potentially:
$ jo < /dev/null
{}
$ MY_ARRAY=(a=1 b=2)
$ jo -a "${MY_ARRAY[@]}" < /dev/null
["a=1","b=2"]
Type coercion:
$ jo -p -- -s a=true b=true -s c=123 d=123 -b e="1" -b f="true" -n g="This is a test" -b h="This is a test"
{
"a": "true",
"b": true,
"c": "123",
"d": 123,
"e": true,
"f": true,
"g": 14,
"h": true
}
$ jo -a -- -s 123 -n "This is a test" -b C_Rocks 456
["123",14,true,456]
Read element values from files: a value which starts with @ is read in plain whereas if it begins with a % it will be base64-encoded and if it starts with : the contents are interpreted as JSON:
$ jo program=jo authors=@AUTHORS
{"program":"jo","authors":"Jan-Piet Mens <jpmens@gmail.com>"}
$ jo filename=AUTHORS content=%AUTHORS
{"filename":"AUTHORS","content":"SmFuLVBpZXQgTWVucyA8anBtZW5zQGdtYWlsLmNvbT4K"}
$ jo nested=:nested.json
{"nested":{"field1":123,"field2":"abc"}}
These characters can be escaped to avoid interpretation:
$ jo name="JP Mens" twitter='\@jpmens'
{"name":"JP Mens","twitter":"@jpmens"}
$ jo char=" " URIescape=\\%20
{"char":" ","URIescape":"%20"}
$ jo action="split window" vimcmd="\:split"
{"action":"split window","vimcmd":":split"}
Read element values from a file in order to overcome ARG_MAX limits during object assignment:
$ ls | jo -a > child.json
$ jo files:=child.json
{"files":["AUTHORS","COPYING","ChangeLog" ....
$ ls *.c | jo -a > source.json; ls *.h | jo -a > headers.json
$ jo -a :source.json :headers.json
[["base64.c","jo.c","json.c"],["base64.h","json.h"]]
Add elements to existing JSON:
$ jo -f source.json 1 | jo -f - 2 3
["base64.c","jo.c","json.c",1,2,3]
$ curl -s 'https://noembed.com/embed?url=https://www.youtube.com/watch?v=dQw4w9WgXcQ' | jo -f - status=Rickrolled
{ ...., "type":"video","author_url":"https://www.youtube.com/user/RickAstleyVEVO","status":"Rickrolled"}
Deduplicate object keys (jo appends duplicate object keys by default):
$ jo a=1 b=2 a=3
{"a":1,"b":2,"a":3}
$ jo -D a=1 b=2 a=3
{"a":3,"b":2}
π OPTIONS π
jo understands the following global options. okay so like, here's the menu:
-aβ Interpret the list of words as array values and produce an array instead of an object. switch up the whole energy β¨-Bβ By default,jointerprets the strings"true"and"false"as boolean elementstrueandfalserespectively, and"null"asnull. Disable with this option. it's giving "I said what I said" vibes π-Dβ Deduplicate object keys. no repeats allowed, bestie π-eβ Ignore empty stdin (i.e. don't produce a diagnostic error when stdin is empty). it's fine, it's chill, no drama πΈ-nβ Do not add keys with empty values. if it's empty, it's not invited to the party π«-pβ Pretty-print the JSON string on output instead of the terse one-line output it prints by default. make it look cute, make it breathe π¬οΈ-vβ Show version and exit. bye bestie π-Vβ Show version as a JSON object and exit. bye but make it JSON π
π BUGS π
Probably. no cap, that's what it says.
If a value given to jo expands to empty in the shell, then jo produces a null in object mode, and might appear to hang in array mode; it is not hanging, rather it's reading stdin. This is not a bug. it's just waiting for you to give it something, like a bestie waiting for your text back π
Numeric values are converted to numbers which can produce undesired results. If you quote a numeric value, jo will make it a string. Compare the following:
$ jo a=1.0
{"a":1}
$ jo a=\"1.0\"
{"a":"1.0"}
Omitting a closing bracket on a nested element causes a diagnostic message to print, but the output contains garbage anyway. This was designed thusly. it's giving chaotic energy but make it intentional π
π«Ά RETURN CODES π«Ά
jo exits with a code 0 on success and non-zero on failure after indicating what caused the failure. so like, if it works it works, if it doesn't it tells you why. communication queen π
β AVAILABILITY β
π CREDITS π
- This program uses
json.[ch], by Joseph A. Adams. shoutout to the icon who made that happen π
π SEE ALSO π
- <https://stedolan.github.io/jq/>
- <https://github.com/micha/jsawk>
- <https://github.com/jtopjian/jsed>
strtod(3)
π¦ AUTHOR π¦
Jan-Piet Mens <http://jpmens.net>
made with love, JSON, and a lot of shell magic π
this page is from the User Manuals, version JO(1), and it's giving dated but iconic. slay bestie, go make some JSON πβ¨
π¦ where this page comes from
- alpine 3.24: jo-doc 1.9-r2 Β· GPL-2.0-or-later
- arch rolling: jo 1.9-3 Β· GPL2
- nixos 26.05: jo 1.9
- nixpkgs unstable: jo 1.9
- opensuse-leap 16.0: jo 1.9-bp160.1.12 Β· GPL-2.0-or-later AND MIT
- opensuse-leap 16.0: jo 1.9-bp160.1.12 Β· GPL-2.0-or-later AND MIT
- opensuse-leap 16.0: jo 1.9-bp160.1.12 Β· GPL-2.0-or-later AND MIT
- opensuse-leap 16.0: jo 1.9-bp160.1.12 Β· GPL-2.0-or-later AND MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms