import sublime
import sublime_plugin
import json

s = sublime.load_settings("Pretty JSON.sublime-settings")


class PrettyjsonCommand(sublime_plugin.TextCommand):
    """ Pretty Print JSON
    """
    def run(self, edit):
        for region in self.view.sel():
            # If no selection, use the entire file as the selection
            if region.empty() and s.get("use_entire_file_if_no_selection"):
                selection = sublime.Region(0, self.view.size())
            else:
                selection = region

            try:
                obj = json.loads(self.view.substr(selection))
                self.view.replace(edit, selection, json.dumps(obj, indent=s.get("indent_size", 4), ensure_ascii=False, sort_keys=s.get("sort_keys", True)))
            except Exception, e:
                sublime.status_message(str(e))

import sublime
import sublime_plugin
import json

s = sublime.load_settings("Pretty JSON.sublime-settings")


class PrettyjsonCommand(sublime_plugin.TextCommand):
    """ Pretty Print JSON
    """
    def run(self, edit):
        for region in self.view.sel():
            # If no selection, use the entire file as the selection
            if region.empty() and s.get("use_entire_file_if_no_selection"):
                selection = sublime.Region(0, self.view.size())
            else:
                selection = region

            try:
                obj = json.loads(self.view.substr(selection))
                self.view.replace(edit, selection, json.dumps(obj, indent=s.get("indent_size", 4), ensure_ascii=False, sort_keys=s.get("sort_keys", True), separators=(',', ': ')))
            except Exception, e:
                sublime.status_message(str(e))

Configure json.dumps() to use an item separator of "," instead of the default ", " to prevent single whitespace at the end of lines.
Configure json.dumps() to use an item separator of "," instead of the default ", " to prevent single whitespace at the end of lines.

Without this option, all prettyfied JSON has one space at the end of each line, which is not so pretty:

{
  "key": "value",_
  "key": "value",_
  "key": "value"
}

This could of course be configured, but with the current simplicity of the package it would probably be overkill.
