logoalt Hacker News

tredre3today at 12:16 AM1 replyview on HN

Powershell commands automatically format the data for you, you can pipe it to grep just fine (I do it all the time). It's just that you can also access it in a structured way if you need to. It's the best of both worlds.

Linux tools that are starting to output raw JSON by default are indeed a nuisance, but how else can you achieve structured output if no standard shell supports it? It's a chicken and egg problem.


Replies

em-beetoday at 1:20 AM

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.