Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A command-line utility to remove quickly comments from a json would be of great use #6

Closed
jmfayard opened this issue Oct 14, 2013 · 8 comments

Comments

@jmfayard
Copy link

Hello fkei,

I need to be able to minify a given json file from the command-line
(I'm on macosx, but with homebrew, node, python, ... everything installed) so that I can do

$ jsonminify manifest-with-comments.json --output manifest.json

actually, that would be even best if the command-line utility would be clever enough to just Do What I Want. "Oh, the filename follows this -with-comments.json conention". So the following command would be a shortcut as the one before

$ jsonminify manifest-with-comments.json

manifest-with-comments.json being here a file in my little free software project https://github.com/internaciulo/search-tab-in-chrome-s-omnibox

I opened an issue there getify#13

@getify replied: No such command-line tool exists in this project. I would suggest asking the maintainer of that npm package if they'll make a command-line tool. It's pretty easy to do, but it just hasn't been done here. I would accept a pull request from someone if they implemented a good one.

Hence this new issue here.

Arigato!

@fkei
Copy link
Owner

fkei commented Oct 16, 2013

Do you want to run from the command line JSON.minify?

Well, I have already made a thing called mjson https://github.com/fkei/node-mjson

Please try it here.

@jmfayard
Copy link
Author

Wow great !

Well excepted a few details
(but as always, details are what matters most)

$ cat ./test/comment.json | mjson.js

People with unix background will warn you that this is a Useless Use of Cat : http://en.wikipedia.org/wiki/Cat_(Unix)#Useless_use_of_cat)

No problem, this does the same job
$ mjson.js < ./test/comment.json

But of course we can do better

$ mjson.js ./test/comment.json

I didn't try if it's possible, but mjson.js --help seems to imply that no.

I hope this is not a restriciton of node.js, that would be weird :(

But wait, standard ouput is fine for using with demo, but it is not what you use once you understand it. More like

$ mjson.js manifest-with-comments.json > manifest.json

or better

$ mjson.js manifest-with-comments.json -o manifest.json

But then there is the suggestion I made, inspired by Ruby on Rails's Convention over configuration principle
http://en.wikipedia.org/wiki/Convention_over_configuration

$ mjson.js manifest-with-comments.json # does the same thing as before since the pattern is recognized

This would be great because:

  • All projects will use the same convention
  • People that will enter the project will be less confused on why there are two json files
  • With this you can do something like
    $ find . -name "*-with-comments.json" | xargs mjson.js
  • Then you can let git triggers it everytime you commit

Then this has to be documented of course, so a documentatinon pull request has to be opened on
getify#13

I am sure this would be really useful, I hope this is not too much to ask :-)

@getify
Copy link

getify commented Oct 16, 2013

@internaciulo

Since mjson is a separate project by @fkei I think the request to change the behavior of that utility belongs there in that repo rather than in this thread for JSON.minify. Again, if someone decides at some point to put in a Pull-Request to my main repo that adds in a CLI utility, I'll be happy to consider it. But until then, it's not really a JSON.minify issue.

Also, note: it's typical that when you make such requests (to change someone's existing code), you actually put in a Pull-Request with the changes implemented, instead of just expecting the author to change something to your desires. If a utility exists, but it's not exactly what you want, and you can't make the changes to his code, I'd suggest you instead just write a little bash-script wrapper to conform it to your desired usage.

@jmfayard
Copy link
Author

This is very off topic, but since you bring it there:

Also, note: it's typical that when you make such requests (to change someone's existing code), you actually put in a Pull-Request with the changes implemented, instead of just expecting the author to change something to your desires. I

I do know that it's typical, but it's really sad, since bug trackers and pull request are aimed primarily at tracking and correcting, well, bugs

But ideas, design, feedback are as bit important as code and bugs and it's just awkard to discuss them with pull requests and bug trackers

That's why many free software projects that could be great never succeed.

They just don't use the apropriate tools like http://uservoice.com/

I promise that I would never use bug trackers to discuss things that are not bugs if I had a choice.

But that's just not the cas right now.

@fkei
Copy link
Owner

fkei commented Oct 17, 2013

I'll implement this future when I find time.

@jmfayard
Copy link
Author

Great 👍

@fkei
Copy link
Owner

fkei commented Oct 17, 2013

Hi

Added a specification that had requested. Please look by using all means.

Document: https://github.com/fkei/node-mjson#command-line-options
Commit : fkei/node-mjson@8bb2acb

$ npm install mjson@0.4.1

Finally, I agree completely with @getify opinion.

@jmfayard
Copy link
Author

Hello fkey,

well first thanks a lot 👍

I have so much projects right now, that I can't do much right now.

But I promise I will look at what you did, see what I can do to improve it or just tell the world if it is already perfect :-D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants