LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-05-2016, 04:21 PM   #1
usao
Member
 
Registered: Dec 2011
Location: Chandler, AZ
Posts: 286

Rep: Reputation: Disabled
What's a good language to use for polling WEB API's and parsing JSON results?


I would like to write a program to poll remote WEB API's and parse the JSON results.
Im familiar with C/Fortran,KSH/Bash,Perl and SQL.

Names I have heard floating around include Python and Java (although this is a complex language). I wold prefer something simple and easy to work with.

Looking for a simple Linux bases scripting language I might interface with postgres. Needs to be able to manipulate Linux shell jobs.
 
Old 08-05-2016, 04:38 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,223

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
BASH, cURL, and a command-line JSON parser.
 
1 members found this post helpful.
Old 08-05-2016, 04:49 PM   #3
usao
Member
 
Registered: Dec 2011
Location: Chandler, AZ
Posts: 286

Original Poster
Rep: Reputation: Disabled
Im good with Bash, but don't know anything about curl. Ill have to look that one up and see what it does.
Is there a name for the "command line JSon" parser? I don't know where to find that. What package is it installed in? Does it work on CentOS? Does it have a yum install 'package' name?
Does it populate postgres or do you have to do that manually in the script?
 
Old 08-05-2016, 04:59 PM   #4
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,223

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
For command-line Json parsers, I don't have a recommendation. However, "jq" and "Jshon" looked interesting last I checked. My best recommendation is to use a search engine to find information on either one, or on use "command-line JSON parser" as a search term.

Nothing will automatically populate postgress. You script that.

Last edited by dugan; 08-05-2016 at 06:14 PM. Reason: Edited so that I sound less like a jerk
 
Old 08-05-2016, 10:17 PM   #5
usao
Member
 
Registered: Dec 2011
Location: Chandler, AZ
Posts: 286

Original Poster
Rep: Reputation: Disabled
I can do that, as long as I can get the JSON values into variables in the script. That's where the parser would help.
 
Old 08-06-2016, 04:17 PM   #6
Doug G
Member
 
Registered: Jul 2013
Posts: 749

Rep: Reputation: Disabled
I'd use php
 
Old 08-07-2016, 09:09 PM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
It seems utterly ridiculous to me to use Bash for any purpose such as this.

When you write "a shell script," you can insert a #!commandprocessorname ("shebang") line at the top of the file, and the shell will invoke whatever command-processor you specify to execute the command. (The end-user will neither know nor care.) Therefore, "the world's your oyster" as to what language you prefer to use.

All of the languages you might pick ... uhh, other than 'bash scripting' ... come with rich, ready-made, fully debugged libraries to handle all of the core tasks that you will face: HTTP, JSON, even complete servers(!).

Thus, your task really becomes choosing a language. and then discovering and leveraging what has already been done(!) to accomplish your intended task. This "build vs. buy" decision is mostly "buy," and the wonderful news is that it won't cost you a dime. Not only "underlying plumbing," but quite possibly "more than 99% of the whole darned thing," might be "sitting on the shelf," waiting for you to find it, take it down and put it to work.

Quote:
Actum Ne Agas: Do Not Do A Thing Already Done.™
"Since you are 'a Good Programmer,'" the first thing that naturally happens when you're faced with a "new" (to you ...!) problem is to "start writing source-code in your head." Unconsciously, you assume that you are going to have to write (from scratch) your solution. These days, this is almost never the case.

Therefore, "Good Programmer" though you might be, your first task should be systems analysis, specification, and then research(!). First, to discover the cornucopia of existing software that might be brought to bear against your problem. Then, to discover (e.g. at GitHub) the many hundreds of existing applications, all of them available to you in source-code form, that already used that software to tackle a problem very similar to yours.

Last edited by sundialsvcs; 08-07-2016 at 09:14 PM.
 
1 members found this post helpful.
Old 08-08-2016, 09:06 AM   #8
usao
Member
 
Registered: Dec 2011
Location: Chandler, AZ
Posts: 286

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Doug G View Post
I'd use php
PHP appears more for creating web pages rather than reading them from a remote server.
 
Old 08-08-2016, 09:10 AM   #9
usao
Member
 
Registered: Dec 2011
Location: Chandler, AZ
Posts: 286

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sundialsvcs View Post
It seems utterly ridiculous to me to use Bash for any purpose such as this.

When you write "a shell script," you can insert a #!commandprocessorname ("shebang") line at the top of the file, and the shell will invoke whatever command-processor you specify to execute the command. (The end-user will neither know nor care.) Therefore, "the world's your oyster" as to what language you prefer to use.

All of the languages you might pick ... uhh, other than 'bash scripting' ... come with rich, ready-made, fully debugged libraries to handle all of the core tasks that you will face: HTTP, JSON, even complete servers(!).

Thus, your task really becomes choosing a language. and then discovering and leveraging what has already been done(!) to accomplish your intended task. This "build vs. buy" decision is mostly "buy," and the wonderful news is that it won't cost you a dime. Not only "underlying plumbing," but quite possibly "more than 99% of the whole darned thing," might be "sitting on the shelf," waiting for you to find it, take it down and put it to work.



"Since you are 'a Good Programmer,'" the first thing that naturally happens when you're faced with a "new" (to you ...!) problem is to "start writing source-code in your head." Unconsciously, you assume that you are going to have to write (from scratch) your solution. These days, this is almost never the case.

Therefore, "Good Programmer" though you might be, your first task should be systems analysis, specification, and then research(!). First, to discover the cornucopia of existing software that might be brought to bear against your problem. Then, to discover (e.g. at GitHub) the many hundreds of existing applications, all of them available to you in source-code form, that already used that software to tackle a problem very similar to yours.
This thread is part of what you call "Research".
My initial discovery phase indicated that "C" was not a good fit for what I was trying to do, in looking around, I found many possible languages which might be a better fit, and the purpose of this thread is to get feedback from those who have already done this (thus making use of what was already done, and not trying to re-invent the wheel).

Im already doing exactly what you suggest in your thread...
 
Old 08-08-2016, 09:18 AM   #10
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Quote:
Originally Posted by usao View Post
PHP appears more for creating web pages rather than reading them from a remote server.
PHP is a rich language very suitable for scripting and certainly VERY suitable for working with APIs and not just to produce web pages. I've maintained PHP scripts that perform extremely complicate work on large (1M+ records) datasets that has had nothing to do with web pages.
 
1 members found this post helpful.
Old 08-08-2016, 09:48 AM   #11
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
most kodi add-ons are written in python. they are essentially scraping urls and title/author/publication/... data from webpages such as you-toob.com/dis-nee.com/...

i usually bash it out using wget.
 
Old 08-08-2016, 10:26 AM   #12
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
I consult the API authoritative documentation.
and get ready to learn some python. Ugly? Hell yes.
Primitive? Runs faster than bash and friends.

Last edited by Habitual; 08-08-2016 at 10:29 AM.
 
Old 08-08-2016, 11:58 AM   #13
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Quote:
Originally Posted by usao View Post
PHP appears more for creating web pages rather than reading them from a remote server.
Code:
$ url="http://www.api.com/jsonpage"
$ php -r 'print_r(json_decode(file_get_contents($argv[1])));' $url
 
Old 08-08-2016, 05:55 PM   #14
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Quote:
Originally Posted by usao View Post
This thread is part of what you call "Research".
My initial discovery phase indicated that "C" was not a good fit for what I was trying to do, in looking around, I found many possible languages which might be a better fit, and the purpose of this thread is to get feedback from those who have already done this (thus making use of what was already done, and not trying to re-invent the wheel).

Im already doing exactly what you suggest in your thread...
Reckon that, "across these many (koff koff ...) decades, now," I've probably used "most of 'em," and I don't reckon I ever did arrive at any "favorites."

"Pick a girl, ask her to marry you, and be genuinely(!) amazed when she says, "Yes!" Then, jump headlong into the rapids and hope for the best." Even though you might, from time to time, "not be entirely satisfied with your decision," the project will be achieved, and maybe she will still love you anyway.

Last edited by sundialsvcs; 08-08-2016 at 05:59 PM.
 
Old 08-08-2016, 06:19 PM   #15
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by usao View Post
PHP appears more for creating web pages rather than reading them from a remote server.
Actually, PHP is a terrific scripting language as well. I'd definitely consider it for such an application.

I use it as a quick prototyping language for things eventually to be written in C/C++, and also have written several large applications in PHP that are part of my own critical infrastructure.

Last edited by astrogeek; 08-08-2016 at 06:22 PM.
 
  


Reply



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] Parsing Javascript To JSON Using Python 3 cin_ Programming 3 05-18-2015 04:08 PM
[SOLVED] Parsing Javascript To JSON cin_ Programming 5 05-18-2015 04:04 PM
A minimalist server monitor API (JSON would cool) for custom server monitoring app? Ultrus Linux - Server 1 02-20-2014 02:28 AM
Google Places API JSon Data trscookie Programming 1 12-08-2013 03:13 PM
PHP ! a good programming language for web ! thaihoabo Programming 10 01-11-2007 08:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:08 AM.

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