jq

jq is a command line tool for processing JSON.

jq Homepage (Documentation)

Installation

Easiest way is usingHomebrew:

brew install jq

Examples

Combined withwxr_to_json, I was able to take my Wordpress site and create JSON entries:

git clone git}github.com:infovore/wxr_to_json.git
cd wxr_to_json
./wxr_to_json.js ~/Downloads/adamkoch.WordPress.2021-08-09.xml > output.json

I can't remember if I even got this working:

for f in $(ls -R **/index.json)
do
  jq -r '"- var id=" + .["wp:post_id"] + "\n- var path=" + (.link | sub("https://www.adamkoch.com/"; "")) + (if (.tidyTags | length > 0) then ("\n- var tags=\"" + (.tidyTags | join(",")) + "\"") else "" end) + "\n- var publishedDate=\"" + (.["wp:post_date_gmt"] | sub(" "; "T") + "Z") + "\"\n" + (.["content:encoded"])' $f > $f.html
  grep -v "^- var.*" $f.html | html2pug > $f.pug
done

I can't remember if I even got this working:

.[] | "insert into vehicle_data values(" + (.year | tostring) + ", '" + (.make | sub("'"; "''"; "g")) + "', '" + (.model | sub("'"; "''"; "g")) + "', '" + (.trim  | sub("'"; "''"; "g")) + "');"


← Back to Code Samples

← Back to Tech