ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

JSONComma

by math2001 ST2/ST3

A Sublime Text plugin to deal with those damn JSON commas!

Details

Installs

  • Total 7K
  • Win 4K
  • OS X 2K
  • Linux 977
Oct 23 Oct 22 Oct 21 Oct 20 Oct 19 Oct 18 Oct 17 Oct 16 Oct 15 Oct 14 Oct 13 Oct 12 Oct 11 Oct 10 Oct 9 Oct 8 Oct 7 Oct 6 Oct 5 Oct 4 Oct 3 Oct 2 Oct 1 Sep 30 Sep 29 Sep 28 Sep 27 Sep 26 Sep 25 Sep 24 Sep 23 Sep 22 Sep 21 Sep 20 Sep 19 Sep 18 Sep 17 Sep 16 Sep 15 Sep 14 Sep 13 Sep 12 Sep 11 Sep 10 Sep 9 Sep 8
Windows 12 11 14 25 23 18 19 14 6 12 17 12 12 19 27 12 5 12 8 21 11 11 11 19 10 25 14 18 24 5 15 21 10 26 25 33 11 9 25 28 25 16 12 7 14 19
OS X 8 3 3 12 11 8 7 8 4 4 14 9 6 14 8 6 3 8 11 9 6 10 3 8 3 10 11 13 15 10 4 12 11 13 16 16 6 9 9 10 10 11 8 5 6 9
Linux 3 5 4 1 10 6 6 4 3 3 4 3 0 10 5 0 2 5 5 6 4 1 3 4 3 6 6 7 5 3 1 6 7 6 7 6 1 5 3 2 3 5 6 1 0 3

Readme

Source
raw.​githubusercontent.​com

JSONComma

JSONComma is a really simple but helpful plugin that, as it's name says, helps managing those damn commas in json.

Examples:

It removes trailling comma

{
     "hello": "world",
-    "not needed": "damn comma",
+    "not needed": "damn comma"
 }

Adds needed commas!

{
-    "hello": "world"
-    "not needed": "damn comma"
+    "hello": "world",
+    "not needed": "damn comma",
     "aList": [
-        "hello" "world"
-        "this" "is" "a nasty ]{ example ] "
-        ["BUT" "IT" "STILL" "WORKS!!"]
+        "hello", "world",
+        "this", "is", "a nasty ]{ example ] ",
+        ["BUT", "IT", "STILL", "WORKS!!"]
     ]
 }

Supports comments

{
-    "hello": "world"
+    "hello": "world",
     // A Comment
-    "not Needed": "damn Comma" // an other
+    "not Needed": "damn Comma", // an other
     // with a second one
     "alist": [
-        "hello" "world"
-        "this" // a comment
-        "is" "a Nasty ]{ Example ] "
-        ["but" "it" "still" "works!!"]
+        "hello", "world",
+        "this", // a comment
+        "is", "a Nasty ]{ Example ] ",
+        ["but", "it", "still", "works!!"]
     ]
 }

Everything mixed up

{
-    "name": "JSONComma" // no space allowed in GitHub repository name
-    "version": "0.1.0" // wait a bit before 1.xxx to detect bugs
+    "name": "JSONComma", // no space allowed in GitHub repository name
+    "version": "0.1.0", // wait a bit before 1.xxx to detect bugs
     "labels": [
-        "json"
-        "JSON"
-        "light"
-        "on_save",
-    ],
+        "json",
+        "JSON",
+        "light",
+        "on_save"
+    ]

 }

Usage

If there is no selection (to be correct, it'd be no non-empty selection), it will format the entire file.

Run the command (json_comma)

Open up the command palette and look for JSONComma: Run. Hit enter, and you're done!

You want to run this as soon as you save?

Pas de probleme! Add this to your settings:

"jsoncomma_on_save": true

Et voila! Each time you'll save a JSON file (or a json-like — more info), JSONComma will be run. Enjoy! :smile:

Installation

Because it is not available on package control for now, you have to add this repo “manually” to your list.

Using package control

  1. search for Package Control: Install Package in the command palette — ctrl+shift+p (might take a few seconds)
  2. search for JSONComma
  3. hit enter :wink:

Using the command line

cd "%APPDATA%\Sublime Text 3\Packages"             # on window
cd ~/Library/Application\ Support/Sublime\ Text\ 3 # on mac
cd ~/.config/sublime-text-3                        # on linux

git clone "https://github.com/math2001/JSONComma"

Which solution do I choose?

It depends of your needs:

  • If you intend to just use JSONComma, then pick the first solution (Package Control), you'll get automatic update.
  • On the opposite side, if you want to tweak it, use the second solution. Note that, to get updates, you'll have to git pull

Contributing

First, you can raise an issue to let me know the bug you've found, the improvement you're thought of, etc… Always raise an issue before you PR me.

If you want to solve this bug/add your feature yourself, here's what I'd like you to do:

  • create a new branch your-feature-name
  • add your feature
  • run the tests (see bellow). They must pass.
  • push and PR me!

How to run the test

If you have a look at the code, you'll see that there is a command json_comma_test, but it is shown nowhere. It is wanted. The final user doesn't care about the test command. So, it is your job to add it to the command palette, bind it to a shortcut, or if you like to complicate your life, run it from the console :smile:

Run the command, a new file will popup and automatically close itself straight away. JSONComma needs a file to run the test because it uses the scope names to detect if it needs to add/remove a comma.

The result will be shown it an output panel though.