logoalt Hacker News

em-beetoday at 1:20 AM0 repliesview on HN

and new shells are developing features to handle structured data like json:

here is an elvish shell command that converts a freetube playlist from json into a list of urls grouped by author:

    for i (cat 'freetube-playlist-favorites.db' | from-json)["videos"] { 
      mkdir -p $i['author']
      print http://youtu.be/$i['videoId'] >> $i['author']/get }
here is one to get a list of devices connected to my zerotier network

    curl -s -H "Authorization: token <redacted>" "https://api.zerotier.com/api/v1/network/<redacted>/member" | 
      all (from-json) | 
      order &key={|d| put $d[name]} | 
      each { |device| 
             var t = (printf "%.0f" (/ $device[lastSeen] 1000))
             if (> 20000000 (- (date '+%s') $t))  { 
               print (date -R --date='@'$t) $device[config][ipAssignments] $device[name] "\n" } }
those are not scripts saved in a file. i run these directly on the commandline. ignore the elvish syntax, focus on the ease of accessing values from the json data. those are just two examples, though i recently discovered an ls replacement that optionally outputs json, that will be interesting to use.