title: Output JSON from Bash script
body: <p>So I have a <code>bash</code> script which outputs details on servers. The problem is that I need the output to be <code>JSON</code>. What is the best way to go about this? Here is the bash script:</p>
  
  <pre><code># Get hostname
  hostname=`hostname -A` 2&gt; /dev/null
  
  # Get distro
  distro=`python -c 'import platform ; print platform.linux_distribution()[0] + " " +        platform.linux_distribution()[1]'` 2&gt; /dev/null
  
  # Get uptime
  if [ -f "/proc/uptime" ]; then
  uptime=`cat /proc/uptime`
  uptime=${uptime%%.*}
  seconds=$(( uptime%60 ))
  minutes=$(( uptime/60%60 ))
  hours=$(( uptime/60/60%24 ))
  days=$(( uptime/60/60/24 ))
  uptime="$days days, $hours hours, $minutes minutes, $seconds seconds"
  else
  uptime=""
  fi
  
  echo $hostname
  echo $distro
  echo $uptime
  </code></pre>
  
  <p>So the output I want is something like:</p>
  
  <pre><code>{"hostname":"server.domain.com", "distro":"CentOS 6.3", "uptime":"5 days, 22 hours, 1 minutes, 41 seconds"}
  </code></pre>
  
  <p>Thanks.</p>