Skip to content

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

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

Closed
1 of 3 tasks
ergonjona opened this issue Apr 10, 2025 · 1 comment
Closed
1 of 3 tasks

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

ergonjona opened this issue Apr 10, 2025 · 1 comment

Comments

@ergonjona
Copy link
Contributor

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
@ergonjona ergonjona added the Bug label Apr 10, 2025
@danielaparker
Copy link
Owner

danielaparker commented Apr 11, 2025

Thanks for raising this. It should be fixed on master. The issue was not with cursors per se, but rather with the implementation of iterators on staj_object_view. The issue was introduced in 1.3.1.

We'll release an updated version 1.3.2 soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants