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

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.