CodeKit2 icon indicating copy to clipboard operation
CodeKit2 copied to clipboard

Request: Minify JSON. lolwut

Open erikwoods opened this issue 11 years ago • 13 comments

I know it might sound weird, but if CodeKit had a minifier for JSON that would be neat. There aren't a lot of reasons to have this, but I can think of a few.

  1. For public static files, it reduces file size - and who doesn't want to do that?
  2. It would be neat if it could filter out comments. I know it's not valid to have comments in JSON but if the minification strips it out... no problem!
  3. It would be REALLY neat to have a pre-compiler for json so that you can use variables and stuff. Maybe something like this already exists and I'm just not aware of it.

There is a json minifier for npm, btw... so I know I'm not the only one who has found it useful.

EDIT: if it's not obvious already, it would be useful to have a source and a minified version of a JSON file - obviously otherwise you can never edit the original in its awesome formatted and commented form.

erikwoods avatar Aug 08 '14 15:08 erikwoods

An interesting idea. I don't need Node stuff to do that; there's a C api that will be orders of magnitude faster than anything written in JavaScript could ever hope to be.

However, suppose you have myfile.json in your project. How is the app supposed to construct the output path? myfile-min.json? Is the file supposed to be minified in-place?

bdkjones avatar Aug 08 '14 18:08 bdkjones

The Node example was just for reference and to show that others have found it to be useful. That minifier actually doesn't strip out comments, so that sucks.

I'd like to treat json files the same way CK2 treats js files I guess.

In my project, I have a 'src' dir and a 'public' dir. All of my 'src' files compile to 'public' - json would be the same, ideally.

But I realize some people like to have their .min files right next to their .whatever files so having both options like you do for js seems like a good idea.

EDIT: having it minified in-place would probably be bad news bears because then you'd never be able to make use of the comments or formatting of the original file.

erikwoods avatar Aug 08 '14 19:08 erikwoods

@bdkjones Hey Bryan! I could definitely see a use for this!

I think there should be an option to either place the minified file in a /public directory or in-place with .min.json tacked on

hudsonperalta avatar Nov 18 '14 16:11 hudsonperalta

Alright; I'll move it up my list. Shouldn't be too hard to implement.

bdkjones avatar Nov 18 '14 18:11 bdkjones

:+1: awesome

erikwoods avatar Nov 18 '14 21:11 erikwoods

+++1 for JSON minification. I'm working on a project right now and I'm butting my head up against not being able to minify the JSON file. I changed the filename from .json to .js, but uglify.js is still failing on the minification step.

tlee1271 avatar Jan 13 '15 02:01 tlee1271

@tlee1271: While @bdkjones is working on this, you can use other things that can do this for you pretty easily outside of CodeKit. I use json-minify for now. It won't allow comments and it won't do it automagically but it works.

erikwoods avatar Jan 15 '15 15:01 erikwoods

Implemented for 2.2.1. Should be out this week; just waiting on Libsass to take 3.2 gold.

bdkjones avatar Mar 24 '15 03:03 bdkjones

To be clear, though: comments aren't supported and the input JSON files have to be valid JSON. But CodeKit will minify them for you and will offer the ability to alphabetize dictionary items by key, which is very handy if your JSON file has to be committed to a repo. Per spec, there is no order to dictionary items in a JSON file.

bdkjones avatar Mar 24 '15 03:03 bdkjones

FUCKYEAH Thanks so much! This is gonna be **awesome**.

erikwoods avatar Mar 24 '15 03:03 erikwoods

You the man @bdkjones thanks!

hudsonperalta avatar Mar 24 '15 11:03 hudsonperalta

@bdkjones I just wanted to thank you again for adding this feature. It auto-detects when I make changes and refreshes. It's fan-fucking beautiful. It's precisely what I was looking for! So stoked. You do good work man.

erikwoods avatar May 19 '15 03:05 erikwoods

Sure thing!

bdkjones avatar May 19 '15 05:05 bdkjones