Skip to content

Strip comments / Minify #294

Description

@gnzlbg

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?

Activity

  1. nlohmann commented on Aug 16, 2016

    @nlohmann
    Owner

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

  2. gnzlbg commented on Aug 17, 2016

    @gnzlbg
    Author

    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?

  3. nlohmann commented on Aug 17, 2016

    @nlohmann
    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.

  4. added this to the Release 3.8.1 milestone on Jun 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions