Processing JSON data on the command line

Processing JSON data on the command line

. 1 min read

Originally posted at: https://blog.mypad.in/processing-json-data-on-the-command-line/

JSON has become the defacto standard of data transfer for a major part of the internet now. Particularly with the ubiquitous usage of mobile apps, pretty much all data is transferred via JSON.

Processing JSON rapidly is a recurring need in data processing.

Multiple libraries exist in Python and R for processing JSON. However, I have a strong preference to process JSON on the command line with tools particularly developed for such purpose.

jq is my favorite command line JSON processor. jq makes processing JSON a pleasure and lot of fun. Its used widely and lots of material is available on the web to help with data wrangling.

I'd like to demonstrate processing my favorite Spinning providers' data from Peloton below.

I've got all the rides to data from Pelton in a file called consolidated-od-classes.json. Typically for data analysis using R or Python I need the data to be transform to csv to be loaded into a data frame for manipulation with data.table

Here is a simple command that does the job:

# generated from other scripts
# download at https://l.mypad.in/peloton-od-classes
output="./data/peloton/consolidated-od-classes.json"

# for tracking performance
start=`date +%s`

result="./data/peloton/result.csv"

echo 'title,id,scheduled_start_time' > $result

jq -r '[.title, .id, .scheduled_start_time] | @csv' $output >> $result

end=`date +%s`

runtime=$((end-start))
echo $runtime

The csv extract is ready!

Screenshot-2020-01-01-at-9.49.02-PM

References


Tags

AWS Analytics Antifragile Apache Spark Apple Apps Arbitrage Automation Awesome BBMP Bangalore Black Swan Bonds Boonex Bootstrap Brokerage Charges CFPB CMS CSS Calypso Camelot Capital Markets Charts Chirp Choropleth Chrome Code Igniter Collections Containerization Converters Cycling DalalBeat Data Analytics Data Journalism Data Mining Data Munging Data Privacy Data Science Databases Debt Design Design Stock DesignStock Diet Django Docker Document Processing Dropbox Electron Electronics Entertainment Entrepreneurship Exercise FFMPEG Facebook Finance Fire TV Stick Fitness Forerunner From-The-News Fun Futures Gaana Garmin General Geocoding Getting Started Ghost Google APIs GraphicsMagick HHVM HTTPS Hackathon Hacks Hardware Health House Keeping Housing IBM BlueMix IBrokers IPinfo Ideas Image Conversion Image Processing Infographics Interactive Brokers Internet Investing IoT Legal Lets Encrypt Mac Machine Learning Mailbox app Mapbox Markdown Marketing Meteor Mockups MongoDB Mortgages Movies Music MyPad MySQL Nativefier Nature Netflix Newsletters Nginx Node.js Notes OCR OSX Open Source OpenCPU Options PDF PHP Pebble Peloton Personal Photography Picture Platforms Plex Portable Apps Productivity Property Tax PyroCMS Quantitative Finance R-Project Random Raspberry Pi Research Resources Reticulate Robot S3 SQLite STT Scraping Security Server Shell Shiny Side Project Sikuli Speech Recognition Spider Pro Spinning Spotify Startup Resources Startups Strategy Sublime Text System Monitoring Tax Terminal Tips To Do Tools Torrent Trading Trends Troubleshooting USElection2016 Ubuntu Unix Valuations Video Conversion Visualization Wagtail Wearables Weekend Fun WhatsApp Wordpress anaconda annie bash catalina cv2 daily coding dailycoding data.table debugging devtools downloader e-Signatures ggplot git go google maps hat-tip iOS iPad iPhone iTunes javascript jupyter logging macos numpy opencv optionality plotly python rstats videos youtube