Jo analysis: how to use shell commands to create JSON
I tried to corrupt the shell script to create JSON. You may have read this in some places:
Echo '{"name": "Jane "}'
If an element contains an environment variable: open double, close single, add variable, open single, blergh.
The script is printed in the following way, but its readability is not improved much:
Printf' {"name": "% s"} \ N' "Jane"
Enter jo:
$ Jo name = Jane
{"Name": "Jane "}
One night I suddenly got an idea. I don't know why it took me so long:
$ Jo time = $ (date + % s) dir = $ HOME
{"Time": 1457195712, "dir": "/Users/jpm "}
BAM! Jo tries to introduce the type, null, Boolean Type, string, and number. It also has an array, which is printed as follows:
$ Jo-p-a spring summer winter
[
"Spring ",
"Summer ",
"Winter"
]
Inspired by HN's comment, I added another hack: If a key value starts with a left braces ({) or a braces ([]), we try to decode the JSON; it allows jo to add objects or arrays.
$ Jo-p name = JP object =$ (jo fruit = Orange [email protected] point =$ (jo x = 10 y = 20) number = 17) Sunday = false
{
"Name": "JP ",
"Object ":{
"Fruit": "Orange ",
"Hungry": false,
"Point ":{
"X": 10,
"Y": 20
},
"Number": 17
},
"Sunday": false
}
Why? I need a lot of JSON to test OwnTracks, and the script looks more convenient.
$ Jo _ type = location \
Cog = $ (RANDOM % 360 ))\
T = u \
Lat = 48.85833 \
Lon = 2.29513 \
Acc = 5 \
Tid = JJ \
Tst = $ (date + % s) | mosquitto_pub-t owntracks/jjolie/test-l
Jo has a user manual. Go and check it out!
Update:
Caius Durling provides jo's Homebrew tap;
Jo has a logo when it is created, and color is authorized by Frederic Cambus;
Shawn Webb adds jo to the HardenedBSD article;
I have converted jo into an automatic tool. This version will be released;
Alessio Sergi has added jo to voidlinux and installed xbps-install-Su jo;
I have created a Win32 release link;
Lance Chen establishes the jo ArchLinux port.