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 15K
  • Win 9K
  • OS X 4K
  • Linux 2K
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 Sep 7 Sep 6 Sep 5 Sep 4 Sep 3 Sep 2 Sep 1 Aug 31 Aug 30 Aug 29 Aug 28 Aug 27 Aug 26 Aug 25 Aug 24 Aug 23 Aug 22 Aug 21 Aug 20 Aug 19 Aug 18 Aug 17 Aug 16 Aug 15 Aug 14 Aug 13 Aug 12 Aug 11 Aug 10 Aug 9 Aug 8
Windows 2 12 11 11 14 17 7 6 19 15 19 13 19 10 16 15 18 11 18 21 6 4 11 12 20 27 17 6 11 16 16 17 23 18 9 9 27 19 15 21 17 7 13 19 21 19
OS X 1 6 10 12 5 9 5 6 10 8 13 3 4 2 3 6 7 6 7 8 2 0 9 16 12 8 9 2 2 9 7 7 5 4 1 3 4 8 12 15 7 7 4 3 4 12
Linux 0 5 1 4 6 3 0 4 1 2 5 6 5 1 2 3 4 4 4 3 2 2 1 5 3 5 2 2 3 2 3 4 6 4 4 2 2 5 4 3 3 3 3 2 3 7

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.