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

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.