diff --git a/Default.sublime-commands b/Default.sublime-commands
index 1b9c623..92ca6cb 100644
--- a/Default.sublime-commands
+++ b/Default.sublime-commands
@@ -1,6 +1,6 @@
[
{
- "caption": "Pretty JSON: Reformat (Pretty Print) JSON",
+ "caption": "Pretty JSON: Format (Pretty Print) JSON",
"command": "pretty_json"
},
{
@@ -8,7 +8,7 @@
"command": "un_pretty_json"
},
{
- "caption": "Pretty JSON: Jq query",
+ "caption": "Pretty JSON: JSON query with ./jq",
"command": "jq_pretty_json"
}
]
\ No newline at end of file
diff --git a/PrettyJson.py b/PrettyJson.py
index a34ad2f..04e8098 100644
--- a/PrettyJson.py
+++ b/PrettyJson.py
@@ -12,15 +12,13 @@ except (ValueError):
import simplejson as json
from simplejson import OrderedDict
-s = sublime.load_settings("Pretty JSON.sublime-settings")
-
jq_exits = False
jq_version = None
import subprocess
try:
- # checking if jq tool is available in PATH so we can use it
+ # checking if ./jq tool is available so we can use it
s = subprocess.Popen(["jq", "--version"], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
out, err = s.communicate()
jq_version = err.decode("utf-8").replace("jq version ", "").strip()
@@ -29,6 +27,9 @@ except OSError:
jq_exits = False
+s = sublime.load_settings("Pretty JSON.sublime-settings")
+
+
class PrettyJsonCommand(sublime_plugin.TextCommand):
""" Pretty Print JSON """
def run(self, edit):
@@ -107,12 +108,18 @@ class UnPrettyJsonCommand(PrettyJsonCommand):
class JqPrettyJson(sublime_plugin.WindowCommand):
"""
- Allows work with jq
+ Allows work with ./jq
"""
def run(self):
- self.window.show_input_panel("Enter JQ query", ".", on_done=self.done, on_change=None, on_cancel=None)
+ if jq_exits:
+ self.window.show_input_panel("Enter ./jq filter expression", ".", on_done=self.done, on_change=None, on_cancel=None)
+ else:
+ sublime.status_message("./jq tool is not available on your system. http://stedolan.github.io/jq")
def get_content(self):
+ """
+ returns content of active view or selected region
+ """
view = self.window.active_view()
selection = ""
for region in view.sel():
diff --git a/README.md b/README.md
index c3acb65..f232bfd 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
[](https://travis-ci.org/dzhibas/SublimePrettyJson)
-Prettify JSON plugin for Sublime Text 2 & 3
+Prettify/Minify/Query JSON plugin for Sublime Text 2 & 3
## Installation
@@ -14,21 +14,25 @@ To prettify JSON, make selection of json and press keys:
- Windows: ctrl+alt+j
- OS X: cmd+ctrl+j
-or through Command Palette Ctrl+Shift+P find "Pretty JSON: Reformat (Pretty Print) JSON"
+or through Command Palette Ctrl+Shift+P find "Pretty JSON: Format (Pretty Print) JSON"
-If selection is empty and configuration entry **use_entire_file_if_no_selection** is true, tries to prettify whole file.
+If selection is empty and configuration entry **use_entire_file_if_no_selection** is true, tries to prettify whole file
-If JSON is not valid it will be displayed in status bar of sublime.
+If JSON is not valid it will be displayed in status bar of Sublime Text
### Compress / Minify JSON
-Using Command Palette Ctrl+Shift+P find "Pretty JSON: Minify (compress) JSON" this will make selection or full buffer as single line JSON which later you can use in command lines or somewhere else
+Using Command Palette Ctrl+Shift+P find "Pretty JSON: Minify (compress) JSON" this will make selection or full buffer as single line JSON which later you can use in command lines (curl/httpie) or somewhere else...
-## jQ usage
+## ./jQ query/filter usage
+
+Demo:
[](http://www.gang.lt/prettyjson.gif)
-if on your machine "[./jq](http://stedolan.github.io/jq/)" tool is available with ctrl+atl+shift+j you can run against your json. output will be opened in new view
+If on your machine "[./jq](http://stedolan.github.io/jq/)" tool is available with ctrl+atl+shift+j you can run against your json. output will be opened in new view so you can once again apply jq on new buffer
+
+You can find instructions of tool here:
http://stedolan.github.io/jq/
@@ -44,13 +48,13 @@ http://stedolan.github.io/jq/
## Using tabs for indentation
-You can change configuration key **indent** to string value "\t" or any other string.
+You can change configuration key **indent** to string value "\t" or any other string
```
"indent" : "\t",
```
-Be sure "Indent Using Spaces" is unchecked otherwise you will not see effect and ST2 will convert it back to spaces.
+Be sure "Indent Using Spaces" is unchecked otherwise you will not see effect and ST2/3 will convert it back to spaces
## Thanks