LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-20-2016, 06:03 AM   #1
usao
Member
 
Registered: Dec 2011
Location: Chandler, AZ
Posts: 286

Rep: Reputation: Disabled
parse json using shell commands?


Is there a way to parse json files using standard linux shell tools?
I don't want to install/learn python/php or other stuff, would prefer to use bash, awk, sed, etc...
It would not be cost/time effective for me to learn python/php for a one-time use senerio. Just need to write a quick automation to parse a json format im getting from a web site. It will be a one-off application, so please don't try to talk me into php/python as that will take weeks to figure out, ill never have another use for it, and I need something quick and easy.
 
Old 12-20-2016, 06:50 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,420

Rep: Reputation: 430Reputation: 430Reputation: 430Reputation: 430Reputation: 430
There's a command called jq for this,

https://stedolan.github.io/jq/tutorial/

https://stedolan.github.io/jq/manual/

You'll probably have it in your distro, if it's not very old.
 
1 members found this post helpful.
Old 12-20-2016, 06:51 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 6,896
Blog Entries: 3

Rep: Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583Reputation: 3583
Quote:
Originally Posted by usao View Post
please don't try to talk me into php/python as that will take weeks to figure out, ill never have another use for it, and I need something quick and easy.
ok. Perl would be a quick and easy way to avoid PHP or Python. :P

JSON is complex enough that you actually have to parse it so awk and sed won't do.

However, there is jq which you could install from your repository and it can do simple extractions.

Edit: oops, too slow, see above

Last edited by Turbocapitalist; 12-20-2016 at 06:52 AM.
 
Old 12-20-2016, 07:25 AM   #4
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,413

Rep: Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540
+1 for jq, I'm using it to parse results from Google Maps API in a bash script and it works just fine!
 
Old 12-20-2016, 07:29 AM   #5
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
I plan to interrogate Kibana with it.
 
Old 12-20-2016, 09:07 AM   #6
usao
Member
 
Registered: Dec 2011
Location: Chandler, AZ
Posts: 286

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Guttorm View Post
There's a command called jq for this,

https://stedolan.github.io/jq/tutorial/

https://stedolan.github.io/jq/manual/

You'll probably have it in your distro, if it's not very old.
Thanks, ill look at JQ and see if I can install it on a Raspberry pi.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] CentOS 7: problem installing Module::IPTables-Parse (JSON::PP 2.27103) NM04 Linux - Software 14 01-13-2015 10:19 PM
LXer: How to parse JSON string via command line on Linux LXer Syndicated Linux News 0 09-05-2013 06:32 PM
Parse JSON using Linux command Stefanus Linux - Newbie 2 11-19-2012 10:25 PM
How to parse in korn shell eddieboo Linux - Newbie 1 04-19-2008 07:06 AM
How to parse 2GB file w linux commands agtlewis Linux - General 5 10-11-2005 08:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration