JSON prettifier for gedit

Just a quick note for those of you that use gedit and want to format json so that it goes from something like this:

{"published":"2011-06-23T11:04:37-04:00","title":"TNC's Ecoregional Portfolio (public)","data_type":"WMS","calculation_params":null,"contributor":"jrfishe1","state":"complete","geometry_types":null,"permissions":[{"permissions":{"download":true,"view":true},"group_id":"everyone"}],"link":"http://geocommons.com/overlays/128841.json","feature_count":0,"icon_link":null,"name":"TNC's Ecoregional Portfolio (public)","extent":[-180.0,-85.0511,180.0,85.0511],"process_notes":"EPSG:4326,EPSG:3857","is_raster":true,"description":"The Nature Conservancy's Ecoregional Portfolio (public version) represents our priority areas for conservation.","short_classification":"Y","author":"The Nature Conservancy","source":"http://maps.tnc.org/","url":"http://maps.tnc.org/ecadpubprodanon/services/portfolio_anon_WM/MapServer/WMSServer?request=GetCapabilities&service=WMS","data_attributes":null,"tags":"conservation,priorities,the nature conservancy,tnc","id":128841,"pagination":{"total":0,"sort":null,"start":0,"limit":1000000},"url_type":"wms","classification":null}

ergh! To something like this

{
  "short_classification": "Y",
  "name": "TNC's Ecoregional Portfolio (public)",
  "icon_link": null,
  "author": "The Nature Conservancy",
  "title": "TNC's Ecoregional Portfolio (public)",
  "url_type": "wms",
  "data_attributes": null,
  "extent": [
    -180.0,
    -85.0511,
    180.0,
    85.0511
  ],
  "published": "2011-06-23T11:04:37-04:00",
  "url": "http://maps.tnc.org/ecadpubprodanon/services/portfolio_anon_WM/MapServer/WMSServer?request=GetCapabilities&service=WMS",
....
  "source": "http://maps.tnc.org/",
  "process_notes": "EPSG:4326,EPSG:3857",
  "state": "complete"
}

How to

Have Ruby. Install json gem.

Enable the external tool plugin in Gedit

Open up Manage External Tools

Create a new item

in the box type

#!/bin/sh
ruby /usr/bin/prettify_json.rb

Voila!

To activate it, load up a json file, then select the new command under tools > external tools

 

 

 

 

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s