Skip to content
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

syntax error on right json string #1276

Closed
wkoroy opened this issue Oct 4, 2018 · 2 comments
Closed

syntax error on right json string #1276

wkoroy opened this issue Oct 4, 2018 · 2 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@wkoroy
Copy link

wkoroy commented Oct 4, 2018

I've been trying to implement this solution and I have been getting the same error:

terminate called after throwing an instance of 'nlohmann::detail::parse_error'
  what():  [json.exception.parse_error.101] parse error at 97: syntax error - unexpected '}'; expected string literal

My code:



  auto s =  create_json_config(); // return content from file jsonstr.txt
   cout<<s;
   json uuid;
   
   uuid.parse(s);
    if (uuid.is_object())
    {
        auto obj = uuid.get<json::object_t>();
        for (auto& kvp : obj)
        {
            std::cout << kvp.first << ":" << kvp.second << "\n";
        }
    }

jsonstr.txt

@pboettch
Copy link
Contributor

pboettch commented Oct 4, 2018

From your jsonstr.txt: Your JSON contains an invalid , at the end of the objects:

{
"index":4,
"frequency":8,
"frame_index":2100,
"displace":256,
},

Here the , after 256 is invalid JSON.

@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Oct 4, 2018
@nlohmann
Copy link
Owner

nlohmann commented Oct 4, 2018

@pboettch is right, and the error message hints at this: after the comma, an object key (i.e., a string literal) is expected. You can verify that jsonstr.txt is invalid by using, e.g., https://jsonlint.com.

@wkoroy wkoroy closed this as completed Oct 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants