Skip to content

Exception when parsing nested JSON object with the cursor API #607

@ergonjona

Description

@ergonjona

Describe the bug
Exception when parsing nested JSON objects with the cursor API

Using the cursor API should not throw exception with valid JSON

When parsing a nested object with the cursor API the final cursor.check_done() throws an exception.

Enumerate the steps to reproduce the bug
Test-Program:

#include "jsoncons/json.hpp"

std::string_view jsondoc = R"({ "prop": { "nested": 123}})";

int main() {
  auto _doc = jsoncons::json::parse(jsondoc);   // this is ok
                                                //
  jsoncons::json_string_cursor cursor(jsondoc);
  for (const auto& [_key, _value] :
      jsoncons::staj_object<std::string_view, jsoncons::json>(cursor)) {
  }
  cursor.check_done(); // check_done() is not happy
                       // what():  Unexpected non-whitespace character after JSON text at line 1 and column 27
  return 0;
}

What compiler, architecture, and operating system?

  • Compiler: gcc (GCC) 14.2.1 20250207
  • Architecture: x64
  • Operating system: Arch Linux

What jsoncons library version?

  • Latest release 1.3.1
  • Other release ______
  • master

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions