Quick JSON Viewer

I've been working with JSON payloads a lot lately for a number of integrations. One of these integrations stores payloads in a text field in ServiceNow. At times they can be large and a bit tough to review and troubleshoot so I looked for a quick way to get the string in a pretty format.

I started off using the JSON Editor Online which was handy but it required multiple steps (copy text, open new or existing tab, paste text). Anyone that knows me knows I'm all about minimizing clicks and keys.

Then I noticed that you can pass an encoded JSON string as a URL parameter (http://jsoneditoronline.org/?json=) to quickly launch the viewer for the string. Now I just needed a quick way to generate that URL and open a new tab. 

I'm currently spending most of my time in Chrome so I installed the Context Menu Search extension. Not surprisingly, this allows you to easily add additional search providers to the context menu.

Now I can highlight text, select the viewer option, and jump right to a new tab with the viewer.

 

Ok, now that's pretty efficient but it can get even better, at least for OS X users in this case. Following on a shortcut I created a while ago to jump to task url from any task number text, I decided to create a keyboard shortcut for the viewer.

Creating an OS X service (this is an alternative to the context menu option)

  • Open Automator
  • Select New Service
  • Add a Run AppleScript activity with the following script:
on run {input, parameters}
--get input as text
set payload to (item 1 of input) as text
return "http://jsoneditoronline.org/?json=" & payload
--send url to display webpages action
end run
  • Below that activity, drag the Display Webpages activity
  • Save the service with a useful name, this will be the service display name in the service menu (since service menu requires extra clicks, we'll add a keyboard shortcut instead
  • Open System Preferences, Keyboard
  • Select Services and find your new service
  • Add a new keyboard shortcut that you'll remember (the trick is finding one that won't conflict with system or application shortcuts, I selected Command-Opt-V)

Now you'll be able to highlight the JSON string on a web site and hit your hotkey to launch a new tab with the viewer.