Jo analysis: how to use shell commands to create JSON

Source: Internet
Author: User

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.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.