Skip to content

ignore_comment=true fails on multiple consecutive lines starting with comments #2330

@mattbement

Description

@mattbement

I know comments are not supported in json, but I'm trying to migrate a project that used YAJL, which has an option for allowing comments, specifically multiple consecutive lines of comments:

// description
// more description
{
...
}

I'm using the parse(...,ignore_comments=true) option, but it's failing on the second comment line. I

What is the issue you have?

Please describe the steps to reproduce the issue.

std::string ss = "//\n//\n{\n}\n";
json j = json::parse(ss,nullptr,true,true);

Can you provide a small but working code example?

std::string ss = "//\n//\n{\n}\n";
json j = json::parse(ss,nullptr,true,true);

What is the expected behavior?

should ignore both lines

And what is the actual behavior instead?

terminate called after throwing an instance of 'nlohmann::detail::parse_error'
what(): [json.exception.parse_error.101] parse error at line 2, column 1: syntax error while parsing value - invalid literal; last read: '//<U+000A>/'
Aborted (core dumped)

Which compiler and operating system are you using?

  • Compiler: gcc 9.2
  • Operating system: Ubuntu 20.04

Which version of the library did you use?

  • latest release version 3.9.0
  • other release - please state the version: ___
  • [x ] the develop branch (35daa5c)

If you experience a compilation error: can you compile and run the unit tests?

  • [x ] yes
  • no - please copy/paste the error message below

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions