Cyberithub

How to Install Jshon on Ubuntu 20.04 LTS (Focal Fossa)

Advertisements

In this article, I will take you through the steps to install Jshon on Ubuntu 20.04 LTS (Focal Fossa). Jshon is a free and open source command line utility to parse, read and create Json. It is created to replace all the fragile Json parsers made from grep/sed/awk as well as heavyweight one line parsers made from python/perl. You can load data to Jshon using stdin or using file, perform actions on it and then display the result on stdout. It is quite easy to use and work with. It is also available to install in almost all the popular systems including Linux. Here we are going to look into the steps to install Jshon on Ubuntu 20.04 LTS based systems.

 

How to Install Jshon on Ubuntu 20.04 LTS (Focal Fossa)

How to Install Jshon on Ubuntu 20.04 LTS (Focal Fossa)

Also Read: How to Install Google Chrome on Ubuntu 22.04 LTS (Jammy Jellyfish)

Advertisements

Step 1: Prerequisites

a) You should have a running Ubuntu 20.04 LTS Server.

b) You should have sudo or root access to run privileged commands.

Advertisements

c) You should have apt or apt-get utility available in your Server.

 

Step 2: Update Your Server

In the first step, you need to install all the available updates and then upgrade the packages to the latest version by using sudo apt update && sudo apt upgrade command as shown below.

Advertisements
cyberithub@ubuntu:~$ sudo apt update && sudo apt upgrade
[sudo] password for cyberithub:
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Hit:2 http://ppa.launchpad.net/flatpak/stable/ubuntu focal InRelease
Hit:3 https://dl.winehq.org/wine-builds/ubuntu focal InRelease
Hit:4 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:5 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:6 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Hit:7 https://download.sublimetext.com apt/stable/ InRelease
Get:8 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:9 http://security.ubuntu.com/ubuntu focal-security/main amd64 c-n-f Metadata [12.5 kB]
Get:10 http://security.ubuntu.com/ubuntu focal-security/universe amd64 c-n-f Metadata [17.6 kB]
Get:11 http://in.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [804 kB]
Get:12 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [2,464 kB]
Get:13 http://in.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [1,046 kB]
Get:14 http://in.archive.ubuntu.com/ubuntu focal-updates/universe i386 Packages [721 kB]
Fetched 5,402 kB in 5s (1,108 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
16 packages can be upgraded. Run 'apt list --upgradable' to see them.
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following package was automatically installed and is no longer required:
libappstream-glib8
Use 'sudo apt autoremove' to remove it.
Get more security updates through Ubuntu Pro with 'esm-apps' enabled:
libopusfile0 libsdl2-2.0-0 libsdl2-2.0-0
Learn more about Ubuntu Pro at https://ubuntu.com/pro
The following packages have been kept back:
xdg-desktop-portal xdg-desktop-portal-gtk
....................................................................

 

Step 3: Install Jshon

In the next step, you can install jshon utility from default Ubuntu repo by using sudo apt install jshon command as shown below. This will download and install the package along with all its dependencies.

cyberithub@ubuntu:~$ sudo apt install jshon
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
libappstream-glib8
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
jshon
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 14.5 kB of archives.
After this operation, 42.0 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu focal/universe amd64 jshon amd64 20131010-3build1 [14.5 kB]
Fetched 14.5 kB in 1s (20.7 kB/s)
Selecting previously unselected package jshon.
(Reading database ... 199919 files and directories currently installed.)
Preparing to unpack .../jshon_20131010-3build1_amd64.deb ...
Unpacking jshon (20131010-3build1) ...
Setting up jshon (20131010-3build1) ...
Processing triggers for man-db (2.9.1-1) ...

 

Step 4: Check Version

After successful installation, you can check the utility version by using jshon --version command as shown below.

Advertisements
cyberithub@ubuntu:~$ jshon --version
20130901

 

Step 5: Verify Installation

You can also check and verify the installed files path by using dpkg -L jshon command as shown below.

cyberithub@ubuntu:~$ dpkg -L jshon
/.
/usr
/usr/bin
/usr/bin/jshon
/usr/share
/usr/share/doc
/usr/share/doc/jshon
/usr/share/doc/jshon/TODO.Debian
/usr/share/doc/jshon/changelog.Debian.gz
/usr/share/doc/jshon/copyright
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/jshon.1.gz

 

Step 6: Using Jshon

Now that we have successfully installed Jshon utility, it is time to use the utility to perform a set of actions on JSON data. For that purpose we need a sample JSON file. In our case, we are using below sample.json file.

cyberithub@ubuntu:~$ nano sample.json
{
 "a":1,
 "b":[true,false,null,"none"],
 "c":{"d":4,"e":5}
}

Now we are going to perform certain different actions on the above json file.

a) -t : (type) returns string, object, array, number, bool, null

cyberithub@ubuntu:~$ jshon -t < sample.json
object

b) -l : (length) returns an integer. Only works on string, object, array.

cyberithub@ubuntu:~$ jshon -l < sample.json
3

c) -k : (keys) returns a newline separated list of keys. Only works on object.

cyberithub@ubuntu:~$ jshon -k < sample.json
a
b
c

d) -e index: (extract) returns json value at "index"

cyberithub@ubuntu:~$ jshon -e c < sample.json
{
 "d": 4,
 "e": 5
}

 

Step 7: Uninstall Jshon

Once you are done using jshon, you can choose to remove the utility from your system by using sudo apt remove jshon command as shown below.

cyberithub@ubuntu:~$ sudo apt remove jshon
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
libappstream-glib8
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED:
jshon
0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded.
After this operation, 42.0 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 199925 files and directories currently installed.)
Removing jshon (20131010-3build1) ...
Processing triggers for man-db (2.9.1-1) ...

Leave a Comment