title: Awk: Formatting output as json
body: <p>I am trying to create a script that will return disk usage for a machine in json format. Here's the command -</p>
  
  <pre><code>df -k $1 | grep -v Filesystem | gawk 'BEGIN { ORS = ""; print " [ "} {printf " { \"name\" : \""$1"\", \"usage\" : \""$5"\", \"mount_point\" : \""$6"\" }" } END { print " ] " }'`
  </code></pre>
  
  <p>The output obtained is -</p>
  
  <pre><code> [  { "name" : "/dev/sda4", "usage" : "36%", "mount_point" : "/" } { "name" : "udev", "usage" : "1%", "mount_point" : "/dev" } { "name" : "tmpfs", "usage" : "0%", "mount_point" : "/dev/shm" } { "name" : "/dev/sda1", "usage" : "17%", "mount_point" : "/boot" }  ]
  </code></pre>
  
  <p>If you observe, there is a comma missing between two json objects. How to I add this in the command?</p>