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

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.