You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
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?
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.
Activity
nlohmann commentedon Aug 16, 2016
For this library, we do not plan to support any input which is not compliant to RFC 7159.
gnzlbg commentedon Aug 17, 2016
That's fine! I think I'll just write a spirit parser to match and strip
// inlinecomments (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 commentedon Aug 17, 2016
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.