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

Strip comments / Minify #294

Closed
gnzlbg opened this issue Aug 16, 2016 · 3 comments · Fixed by #2212
Closed

Strip comments / Minify #294

gnzlbg opened this issue Aug 16, 2016 · 3 comments · Fixed by #2212
Labels
kind: enhancement/improvement kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@gnzlbg
Copy link

gnzlbg commented Aug 16, 2016

While comments are not part of JSON, some people (particularly those writting JSON files by hand sometimes add comments to them). That makes those files not JSON anymore. The typical solution when one wants to process one of those files as JSON is to "minify" them first.

Is it possible to strip comments / minify json files before parsing them as json?

@nlohmann
Copy link
Owner

For this library, we do not plan to support any input which is not compliant to RFC 7159.

@gnzlbg
Copy link
Author

gnzlbg commented Aug 17, 2016

That's fine! I think I'll just write a spirit parser to match and strip // inline comments (which is what I just need) in a pre-processing step tomorrow. Do you think that trying to extend the json parser of this library would be easier? Or do you happen know/use a library to minify json-like data to json?

@nlohmann
Copy link
Owner

You could edit file src/json.hpp.re2c. It contains a re2c lexer (see function basic_json::lexer::scan) and all you would need to do is to add a regex for comments like "//"[^\n]* or so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement/improvement kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants